[Amis-vcs] SF.net SVN: amis: [2197] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2007-10-14 13:34:10
|
Revision: 2197 http://amis.svn.sourceforge.net/amis/?rev=2197&view=rev Author: daniel_weck Date: 2007-10-14 06:34:13 -0700 (Sun, 14 Oct 2007) Log Message: ----------- - Daniel Weck Major Commit * Added AccessibleUi backend (it's wired and works fine with the default loaded language pack: eng-US) * Added hooks to the UI, the top menu kinda works (because its contents have changed since 2.6, things are not quite right...but the framework seems to work fine) * I had a hard time with CoInitialize AppartmentThreaded vs Multithreaded, because of the fact that AMIS now runs at least 3 activeX components: IE-HTML view, Vupp, SAPI-TTS. It seems to work though, but of course we'll only know for sure when all the UI self-voicing hooks are in place. * Oh...and the code is a mess, but I need to test stuff before adding new classes and/or projects that will screw the linking of the VC++ solution. Modified Paths: -------------- branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.cpp branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.h branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AudioSequencePlayer.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/TTSPlayer.cpp branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h branches/amis3/AmisGuiMFC2/include/gui/MainFrm.h branches/amis3/AmisGuiMFC2/src/Preferences.cpp branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp branches/amis3/AmisGuiMFC2/src/gui/HtmlView.cpp branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp branches/amis3/AmisGuiMFC2/src/gui/MenuManip.cpp Added Paths: ----------- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUIDataReader.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUiDataReader.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPromptReader.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPromptReader.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Container.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Container.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/DataTree.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/DataTree.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Dialog.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Dialog.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/DialogControl.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/DialogControl.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/IniFile.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/IniFile.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Label.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Label.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/LabelList.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/LabelList.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Prompt.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Prompt.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/PromptResolver.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/PromptResolver.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/StdAfx.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/StdAfx.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Switch.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Switch.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/UiItem.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/UiItem.h branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/UiMediaTypes.cpp branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/UiMediaTypes.h branches/amis3/AmisGuiMFC2/PreTranslateMessageHandler.cpp branches/amis3/AmisGuiMFC2/PreTranslateMessageHandler.h Modified: branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.cpp =================================================================== --- branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.cpp 2007-10-14 01:59:13 UTC (rev 2196) +++ branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.cpp 2007-10-14 13:34:13 UTC (rev 2197) @@ -221,7 +221,7 @@ // Initialize COM engine for use by this thread //CoInitialize(NULL); //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - CoInitializeEx(NULL, COINIT_MULTITHREADED); + //CoInitializeEx(NULL, COINIT_MULTITHREADED); RegisterOCX(); @@ -265,7 +265,7 @@ logSession("Destruct"); - CoUninitialize(); + //CoUninitialize(); UnregisterOCX(); } @@ -281,6 +281,10 @@ bInitialized = FALSE; bFileLoaded = FALSE; + //CoInitialize(NULL); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + //CoInitializeEx(NULL, COINIT_MULTITHREADED); + // Here we start creating a FilterGraph object and derivate several // interfaces from the object. @@ -292,6 +296,8 @@ return false; } + CoUninitialize(); + bCatchEvents = true; //LPDWORD lpdwThreadID; unsigned long lpdwThreadID; @@ -303,6 +309,7 @@ startPosition = 0; bInitialized = TRUE; + return true; } Modified: branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.h =================================================================== --- branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.h 2007-10-14 01:59:13 UTC (rev 2196) +++ branches/amis3/AmisAudio/TPBReader2/dmp/DmpCtl.h 2007-10-14 13:34:13 UTC (rev 2197) @@ -126,8 +126,8 @@ bool bSelfBreak = false; //CoInitialize(NULL); - //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - CoInitializeEx(NULL, COINIT_MULTITHREADED); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + //CoInitializeEx(NULL, COINIT_MULTITHREADED); CDmpCtrl *pDMP = (CDmpCtrl*)lpParam; IMediaEvent *pIME; Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2007-10-14 01:59:13 UTC (rev 2196) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2007-10-14 13:34:13 UTC (rev 2197) @@ -413,6 +413,215 @@ </Filter> </Filter> </Filter> + <Filter + Name="AccessibleUi" + Filter=""> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AccessibleUIDataReader.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AccessibleUiDataReader.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Action.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Action.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AudioPrompt.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AudioPrompt.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AudioPromptReader.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\AudioPromptReader.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Container.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Container.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\DataTree.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\DataTree.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Dialog.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Dialog.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\DialogControl.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\DialogControl.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\IniFile.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\IniFile.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Label.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Label.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\LabelList.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\LabelList.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Prompt.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Prompt.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\PromptResolver.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\PromptResolver.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\StdAfx.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0" + ObjectFile="$(IntDir)/$(InputName)1.obj"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\StdAfx.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Switch.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\Switch.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\UiItem.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\UiItem.h"> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\UiMediaTypes.cpp"> + <FileConfiguration + Name="Debug|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> + </File> + <File + RelativePath=".\AmisSelfVoicing\AccessibleUI\UiMediaTypes.h"> + </File> + </Filter> <File RelativePath=".\amis.ico"> </File> @@ -444,6 +653,12 @@ RelativePath=".\flag.ico"> </File> <File + RelativePath=".\PreTranslateMessageHandler.cpp"> + </File> + <File + RelativePath=".\PreTranslateMessageHandler.h"> + </File> + <File RelativePath=".\resource.h"> </File> <File Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUIDataReader.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUIDataReader.cpp (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUIDataReader.cpp 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,1222 @@ +//xerces includes + + +#include <xercesc/util/XMLString.hpp> +#include <xercesc/sax2/Attributes.hpp> +#include <xercesc/sax/SAXParseException.hpp> +#include <xercesc/sax/SAXException.hpp> +#include <xercesc/sax/HandlerBase.hpp> + +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/util/TransService.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/XMLReaderFactory.hpp> + +#include "./IniFile.h" + +#include <vector> +#include <string> + +#include "AccessibleUiDataReader.h" +#include "Switch.h" + +#include "../AmisGuiMFC2/include/Preferences.h" +#include "../AmisCore/include/util/FilePathTools.h" + +// DanToDo: The following includes did not survive the Amis3 architecture, so I must find equivalent functions/utilities elsewhere now. +//#include "../Brain/AmisBrain.h" +//#include "../Brain/PrefsReader.h" +//#include "../../AmisCommon/AmisCommon.h" +//#include "../Brain/trim.h" + +namespace AccessibleUi +{ +DataReader::DataReader() +{ + mUiItems.empty(); + mpRecentLabel = NULL; + mpRecentTextNode = NULL; + mpData = NULL; + mpRecentSwitch = NULL; + mCollectedText.empty(); +} + +DataReader::~DataReader() +{ + +} + +void DataReader::setAppPath(string appPath) { + mAppPath = appPath; +} + +string DataReader::getIniFilePath() { + if (! mIniFilePath.empty()) return mIniFilePath; + + mIniFilePath = amis::Preferences::Instance()->mUiLang; + mIniFilePath = amis::util::FilePathTools::goRelativePath(mAppPath, mIniFilePath); + mIniFilePath = amis::util::FilePathTools::goRelativePath(mIniFilePath, "resource.h.ini"); + mIniFilePath = amis::util::FilePathTools::getAsLocalFilePath(mIniFilePath); + + return mIniFilePath; +} + +//-------------- +//start parsing the file and filling in the data model (passed in as pData) +amis::Error DataReader::readFile(string inputFilepath, AccessibleUi::DataTree* pData) +{ + amis::Error err; + + SAX2XMLReader* parser = NULL; + + mUiItems.empty(); + mpRecentLabel = NULL; + mpRecentTextNode = NULL; + mpData = NULL; + mpRecentPrompt = NULL; + mbFlag_GetChars = false; + mpRecentLabelList = NULL; + mbFlag_ProcessingGeneralPrompts = false; + mbFlag_ProcessingPromptItemRefs = false; + + mBuildErrorFlag = amis::OK; + mBuildErrorMsg = ""; + + mpData = pData; + mFilepath = amis::util::FilePathTools::getAsLocalFilePath(inputFilepath); + + const char* cp_file = NULL; + cp_file = mFilepath.c_str(); + + try + { + XMLPlatformUtils::Initialize(); + } + + catch (const XMLException& e) + { + + //MEMORY LEAK VERIFIED + char* xerces_msg = NULL; + + xerces_msg = XMLString::transcode(e.getMessage()); + + mBuildErrorFlag = amis::PARSE_ERROR; + mBuildErrorMsg = "Fatal error while processing *" + mFilepath + + "* Xerces signalled: \"" + xerces_msg + "\""; + + XMLString::release(&xerces_msg); + + err.setCode(mBuildErrorFlag); + err.setMessage(mBuildErrorMsg); + + return err; + + } + + //create an XMLReader object + parser = XMLReaderFactory::createXMLReader(); + parser->setContentHandler(this); + parser->setErrorHandler(this); + + parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false); + parser->setFeature(XMLUni::fgSAX2CoreValidation, false); + + + try + { + parser->parse(cp_file); + } + catch (const XMLException& e) + { + //MEMORY LEAK VERIFIED + char* xerces_msg = NULL; + + xerces_msg = XMLString::transcode(e.getMessage()); + + mBuildErrorFlag = amis::PARSE_ERROR; + mBuildErrorMsg = "Fatal error while processing *" + mFilepath + + "* Xerces signalled: \"" + xerces_msg + "\""; + + XMLString::release(&xerces_msg); + + err.setCode(mBuildErrorFlag); + err.setMessage(mBuildErrorMsg); + + return err; + + } + + delete parser; + XMLPlatformUtils::Terminate(); + + err.setCode(mBuildErrorFlag); + err.setMessage(mBuildErrorMsg); + + //resolve prompt items + mpData->resolvePromptItemsWithRefIds(); + + return err; +} + +//-------------- +//xerces' start element function +void DataReader::startElement(const XMLCh* const uri, + const XMLCh* const localname, + const XMLCh* const qname, + const Attributes& attributes) +{ + char* node_name = XMLString::transcode(qname); + + //container element + if (strcmp(node_name, "container") == 0) + { + Container* p_container = new Container(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("id"); + attr = XMLString::transcode(attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_container->setId(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("accelerator"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + //p_container->setKeyboardAccelerator(attr_tmpstr); + XMLString::release(&attr); + } + Container* p_parent_container = NULL; + + p_parent_container = (Container*)findMostRecentUiItem(CONTAINER); + + if (p_parent_container != NULL) + { + p_parent_container->addChildItem(p_container); + } + else + { + mpData->addContainer(p_container); + } + + mUiItems.push_back(p_container); + + } + + + + //action element + else if (strcmp(node_name, "action") == 0) + { + Container* p_container = NULL; + p_container = (Container*)findMostRecentUiItem(CONTAINER); + + if (p_container != NULL) + { + Action* p_action = new Action(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mfcid"); + attr = XMLString::transcode(attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + + int valueInt; + if (attr_tmpstr.compare("IDOK") == 0) { + valueInt = 1; + } else if (attr_tmpstr.compare("IDCANCEL") == 0) { + valueInt = 2; + } else { + string valueStr = CIniFile::GetValue(attr_tmpstr, "resources", getIniFilePath()); + CIniFile::string2int(valueStr.c_str(), valueInt); + } + p_action->setMfcId(valueInt); + + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("widget"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_action->setWidgetCategories(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("accelerator"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + //p_action->setKeyboardAccelerator(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("condition"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_action->setCondition(attr_tmpstr); + XMLString::release(&attr); + } + + if (mpRecentSwitch != NULL) + { + mpRecentSwitch->addAction(p_action); + } + else + { + p_container->addChildItem(p_action); + } + + mUiItems.push_back(p_action); + + } + + } + + //caption or description element + else if (strcmp(node_name, "caption") == 0 || + strcmp(node_name, "description") == 0 || + strcmp(node_name, "accelerator") == 0 || + strcmp(node_name, "mnemonic") == 0) + { + UiItem* p_item = NULL; + p_item = mUiItems.back(); + + if (p_item != NULL) + { + Label* p_label = new Label(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mfcid"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + + int valueInt; + if (attr_tmpstr.compare("IDOK") == 0) { + valueInt = 1; + } else if (attr_tmpstr.compare("IDCANCEL") == 0) { + valueInt = 2; + } else { + string valueStr = CIniFile::GetValue(attr_tmpstr, "resources", getIniFilePath()); + CIniFile::string2int(valueStr.c_str(), valueInt); + } + p_label->setMfcId(valueInt); + + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("condition"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_label->setCondition(attr_tmpstr); + XMLString::release(&attr); + } + + if (strcmp(node_name, "caption") == 0) + { + p_label->setType(CAPTION); + + if (mpRecentSwitch != NULL && + mpRecentSwitch->getSwitchType() == CAPTIONSWITCH) + { + mpRecentSwitch->addLabel(p_label); + } + else + { + if (mpRecentLabelList != NULL) + { + mpRecentLabelList->addLabel(p_label); + } + else + { + p_item->setCaption(p_label); + } + } + } + else if (strcmp(node_name, "mnemonic") == 0 && p_item->getUiItemType() == ACTION) + { + p_label->setType(MNEMONIC); + if (mpRecentLabelList != NULL) + { + mpRecentLabelList->addLabel(p_label); + } + else + { + ((Action*)p_item)->setMnemonic(p_label); + } + } + else if (strcmp(node_name, "accelerator") == 0 && p_item->getUiItemType() == ACTION) + { + p_label->setType(ACCELERATOR); + if (mpRecentLabelList != NULL) + { + mpRecentLabelList->addLabel(p_label); + } + else + { + ((Action*)p_item)->setKeyboardAccelerator(p_label); + } + } + else if (strcmp(node_name, "accelerator") == 0 && p_item->getUiItemType() == CONTAINER) + { + p_label->setType(ACCELERATOR); + if (mpRecentLabelList != NULL) + { + mpRecentLabelList->addLabel(p_label); + } + else + { + ((Container*)p_item)->setKeyboardAccelerator(p_label); + } + } + else + { + p_label->setType(DESCRIPTION); + + if (mpRecentSwitch != NULL && + mpRecentSwitch->getSwitchType() == DESCRIPTIONSWITCH) + { + mpRecentSwitch->addLabel(p_label); + } + else + { + if (mpRecentLabelList != NULL) + { + mpRecentLabelList->addLabel(p_label); + } + else + { + p_item->setDescription(p_label); + } + } + } + + mpRecentLabel = p_label; + } + } + + //text element + else if (strcmp(node_name, "text") == 0) + { + if (mpRecentLabel != NULL && mpRecentPrompt == NULL) + { + TextNode* p_text = new TextNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mnemonic"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_text->setMnemonic(attr_tmpstr); + XMLString::release(&attr); + } + + mpRecentTextNode = (amis::TextNode*)p_text; + + + TextAudioPair* p_pair = NULL; + p_pair = mpRecentLabel->getContents(); + + //if a text-audio pair hasn't been started for the current label + //then make one + if (p_pair == NULL) + { + p_pair = new TextAudioPair(); + mpRecentLabel->setContents(p_pair); + } + + p_pair->setText(p_text); + + mbFlag_GetChars = true; + } + //if there is no label open but there is a prompt open, then the + //text node should go on its last item, if exists + else if (mpRecentPrompt != NULL) + { + int sz = mpRecentPrompt->getNumberOfItems(); + if (sz > 0) + { + PromptItemBase* p_item = mpRecentPrompt->getItem(sz-1); + + if (p_item->getPromptItemType() == PROMPT_ITEM) + { + TextNode* p_text = new TextNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mnemonic"); + attr = XMLString::transcode(attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_text->setMnemonic(attr_tmpstr); + XMLString::release(&attr); + } + + mpRecentTextNode = (amis::TextNode*)p_text; + + mbFlag_GetChars = true; + p_item->getContents()->setText(p_text); + } + } + } + else if (this->mbFlag_ProcessingPromptItemRefs == true) + { + int last_prompt_item = mpData->getNumPromptItems(); + if (last_prompt_item > 0) + { + PromptItem* p_item = NULL; + p_item = mpData->getPromptItem(last_prompt_item-1); + + if (p_item != NULL) + { + TextNode* p_text = new TextNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mnemonic"); + attr = XMLString::transcode(attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_text->setMnemonic(attr_tmpstr); + XMLString::release(&attr); + } + + mpRecentTextNode = (amis::TextNode*)p_text; + + mbFlag_GetChars = true; + p_item->getContents()->setText(p_text); + } + } + } + } + + //audio element + else if (strcmp(node_name, "audio") == 0) + { + if (mpRecentLabel != NULL && mpRecentPrompt == NULL) + { + amis::AudioNode* p_audio = new amis::AudioNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("src"); + + attr = XMLString::transcode + (attributes.getValue(attr_name)); + + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_audio->setSrc(attr_tmpstr); + XMLString::release(&attr); + } + + TextAudioPair* p_pair = NULL; + p_pair = mpRecentLabel->getContents(); + + //if a text-audio pair hasn't been started for the current label + //then make one + if (p_pair == NULL) + { + p_pair = new TextAudioPair(); + mpRecentLabel->setContents(p_pair); + } + + p_pair->setAudio(p_audio); + } + + //if there is no label open but there is a prompt open, then the + //audio node should go on its last item, if exists + else if (mpRecentPrompt != NULL) + { + int sz = mpRecentPrompt->getNumberOfItems(); + if (sz > 0) + { + PromptItemBase* p_item = mpRecentPrompt->getItem(sz-1); + + if (p_item->getPromptItemType() == PROMPT_ITEM) + { + amis::AudioNode* p_audio = new amis::AudioNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("src"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_audio->setSrc(attr_tmpstr); + XMLString::release(&attr); + } + + + p_item->getContents()->setAudio(p_audio); + } + } + } + else if (this->mbFlag_ProcessingPromptItemRefs == true) + { + int last_prompt_item = mpData->getNumPromptItems(); + if (last_prompt_item > 0) + { + PromptItem* p_item = NULL; + p_item = mpData->getPromptItem(last_prompt_item-1); + + if (p_item != NULL) + { + amis::AudioNode* p_audio = new amis::AudioNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("src"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_audio->setSrc(attr_tmpstr); + XMLString::release(&attr); + } + + p_item->getContents()->setAudio(p_audio); + } + } + } + } + + //icon element + else if (strcmp(node_name, "icon") == 0) + { + Action* p_action = NULL; + p_action = (Action*)findMostRecentUiItem(ACTION); + + if (p_action != NULL) + { + ImageNode* p_image = new ImageNode(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("type"); + + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + if (strcmp(attr, "smallIcon") == 0) + { + p_image->setImageType(SMALL_ICON); + } + else if(strcmp(attr, "largeIcon") == 0) + { + p_image->setImageType(LARGE_ICON); + } + + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("src"); + + attr = XMLString::transcode + (attributes.getValue(attr_name)); + + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_image->setSrc(attr_tmpstr); + XMLString::release(&attr); + } + + + p_action->addImage(p_image); + } + } + + //dialog element + else if (strcmp(node_name, "dialog") == 0) + { + Dialog* p_dialog = new Dialog(); + + mUiItems.push_back(p_dialog); + + mpData->addDialog(p_dialog); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mfcid"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + + int valueInt; + if (attr_tmpstr.compare("IDOK") == 0) { + valueInt = 1; + } else if (attr_tmpstr.compare("IDCANCEL") == 0) { + valueInt = 2; + } else { + string valueStr = CIniFile::GetValue(attr_tmpstr, "resources", getIniFilePath()); + CIniFile::string2int(valueStr.c_str(), valueInt); + } + p_dialog->setMfcId(valueInt); + + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("id"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_dialog->setId(attr_tmpstr); + XMLString::release(&attr); + } + + + } + else if (strcmp(node_name, "control") == 0) + { + + Dialog* p_dialog = NULL; + p_dialog = (Dialog*)findMostRecentUiItem(DIALOG); + + if (p_dialog != NULL) + { + DialogControl* p_dlg_control = new DialogControl(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("mfcid"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + + int valueInt; + if (attr_tmpstr.compare("IDOK") == 0) { + valueInt = 1; + } else if (attr_tmpstr.compare("IDCANCEL") == 0) { + valueInt = 2; + } else { + string valueStr = CIniFile::GetValue(attr_tmpstr, "resources", getIniFilePath()); + CIniFile::string2int(valueStr.c_str(), valueInt); + } + p_dlg_control->setMfcId(valueInt); + + + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("widget"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_dlg_control->setWidgetCategories(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("id"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_dlg_control->setId(attr_tmpstr); + XMLString::release(&attr); + } + + p_dialog->addChildControl(p_dlg_control); + + mUiItems.push_back(p_dlg_control); + } + + + } + else if (strcmp(node_name, "list") == 0) + { + LabelList* p_list = new LabelList(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("repeat"); + + attr = XMLString::transcode + (attributes.getValue(attr_name)); + + XMLString::release(&attr_name); + + if (attr != NULL) + { + if (strcmp(attr, "yes") == 0) + p_list->setRepeat(true); + else + p_list->setRepeat(false); + + XMLString::release(&attr); + } + + mpRecentLabelList = p_list; + + UiItem* p_item = NULL; + p_item = mUiItems.back(); + + if (p_item != NULL) + p_item->setLabelList(p_list); + } + else if (strcmp(node_name, "switch") == 0) + { + if (mUiItems.size() > 0) + { + Switch* p_switch = new Switch(); + mUiItems.back()->setSwitch(p_switch); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("element"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + if (strcmp(attr, "action") == 0) + p_switch->setSwitchType(ACTIONSWITCH); + else if (strcmp(attr, "caption") == 0) + p_switch->setSwitchType(CAPTIONSWITCH); + else if (strcmp(attr, "description") == 0) + p_switch->setSwitchType(DESCRIPTIONSWITCH); + + XMLString::release(&attr); + } + + mpRecentSwitch = p_switch; + } + } + else if (strcmp(node_name, "prompt") == 0) + { + Prompt* p_prompt = new Prompt(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("id"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_prompt->setId(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("type"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_prompt->setType(attr_tmpstr); + XMLString::release(&attr); + } + + this->mpRecentPrompt = p_prompt; + + //if we are processing a label, then the prompt belongs to it + if (mpRecentLabel != NULL) + { + mpRecentLabel->setPrompt(mpRecentPrompt); + } + else if (this->mbFlag_ProcessingGeneralPrompts == true) + { + mpData->addPrompt(mpRecentPrompt); + } + + //else it belongs to a dialog + else + { + Dialog* p_dlg = NULL; + p_dlg = (Dialog*)findMostRecentUiItem(DIALOG); + if (p_dlg != NULL) + { + p_dlg->addPrompt(mpRecentPrompt); + } + } + } + else if (strcmp(node_name, "promptVar") == 0) + { + if (mpRecentPrompt == NULL) + { + mpRecentPrompt = new Prompt(); + + //if we are processing a label, then the prompt belongs to it + if (mpRecentLabel != NULL) + { + mpRecentLabel->setPrompt(mpRecentPrompt); + } + } + + PromptVar* p_var = new PromptVar(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("name"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_var->setName(attr_tmpstr); + XMLString::release(&attr); + } + + //MEMORY LEAK VERIFIED + attr = NULL; + attr_name = XMLString::transcode("param"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_var->setParam(attr_tmpstr); + XMLString::release(&attr); + } + + + mpRecentPrompt->addItem(p_var); + } + else if (strcmp(node_name, "promptItem") == 0) + { + if (mpRecentPrompt == NULL && this->mbFlag_ProcessingPromptItemRefs == false) + { + mpRecentPrompt = new Prompt(); + //if we are processing a label, then the prompt belongs to it + if (mpRecentLabel != NULL) + { + mpRecentLabel->setPrompt(mpRecentPrompt); + } + } + + PromptItem* p_item = new PromptItem(); + + //MEMORY LEAK VERIFIED + char* attr = NULL; + XMLCh* attr_name = XMLString::transcode("refid"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_item->setRefId(attr_tmpstr); + XMLString::release(&attr); + + //add this to the temporary list of things that need to be resolved + mpData->addForResolution(p_item); + } + + //if there was no refid, then this promptItem will have child contents + if (attr == NULL) + { + TextAudioPair* p_pair = new TextAudioPair(); + p_item->setContents(p_pair); + } + + attr = NULL; + attr_name = XMLString::transcode("id"); + attr = XMLString::transcode + (attributes.getValue(attr_name)); + XMLString::release(&attr_name); + if (attr != NULL) + { + std::string attr_tmpstr; + attr_tmpstr.assign(attr); + p_item->setId(attr_tmpstr); + XMLString::release(&attr); + } + + //if we are not processing prompt item refs + //then mpRecentPrompt will exist (either from a prior iteration or + //created above in this else-if block + if (this->mbFlag_ProcessingPromptItemRefs == false) + { + mpRecentPrompt->addItem(p_item); + } + //otherwise, if we are processing the promptItemRefs section + //add it to the data tree + else + { + mpData->addPromptItem(p_item); + } + + } + else if (strcmp(node_name, "generalPrompts") == 0) + { + this->mbFlag_ProcessingGeneralPrompts = true; + } + else if (strcmp(node_name, "promptItemRefs") == 0) + { + this->mbFlag_ProcessingPromptItemRefs = true; + } + else + { + //not recognized + } + + + + XMLString::release(&node_name); +} + +//-------------------------------------------------- +//! (SAX Event) close this element +//-------------------------------------------------- +void DataReader::endElement( const XMLCh* const uri, + const XMLCh* const localname, + const XMLCh* const qname) +{ + //local variable + char* element_name = XMLString::transcode(qname); + + //if it's a ui item + if (strcmp (element_name, "container") == 0 || + strcmp(element_name, "action") == 0 || + strcmp(element_name, "dialog") == 0 || + strcmp(element_name, "control") == 0) + { + //pop it off the stack + mUiItems.pop_back(); + } + //if it was a TEXT or NOTE element, get the accumulated text string and put it on the node + else if (strcmp(element_name, "text") == 0 || + strcmp(element_name, "note") == 0) + { + if (mpRecentTextNode != NULL) + mpRecentTextNode->setTextString(mCollectedText); + + mCollectedText.erase(); + mbFlag_GetChars = false; + mpRecentTextNode = NULL; + } + + + else if(strcmp(element_name, "caption") == 0 || + strcmp(element_name, "description") == 0) + { + mpRecentLabel = NULL; + mpRecentPrompt = NULL; + } + + else if (strcmp(element_name, "switch") == 0) + { + mpRecentSwitch = NULL; + } + + else if(strcmp(element_name, "prompt") == 0) + { + mpRecentPrompt = NULL; + + } + else if (strcmp(element_name, "list") == 0) + { + mpRecentLabelList = NULL; + } + else if (strcmp(element_name, "generalPrompts") == 0) + { + this->mbFlag_ProcessingGeneralPrompts = false; + } + else if (strcmp(element_name, "promptItemRefs") == 0) + { + this->mbFlag_ProcessingPromptItemRefs = false; + } + + + XMLString::release(&element_name); + +} + +void DataReader::characters(const XMLCh *const chars, const unsigned int length) +{ + if (mbFlag_GetChars == true) + { + mCollectedText.append((wchar_t*)chars); + } + +} + +//------------------ +//xerces fatal error +void DataReader::fatalError(const SAXParseException& e) +{ + char* xerces_msg = NULL; + + xerces_msg = XMLString::transcode(e.getMessage()); + + mBuildErrorFlag = amis::PARSE_ERROR; + mBuildErrorMsg = "Fatal error while processing *" + mFilepath + + "* Xerces signalled: \"" + xerces_msg + "\""; + + XMLString::release(&xerces_msg); +} + +void DataReader::error(const SAXParseException& e) +{ + char* xerces_msg = NULL; + + xerces_msg = XMLString::transcode(e.getMessage()); + + mBuildErrorFlag = amis::PARSE_ERROR; + mBuildErrorMsg = "Error while processing *" + mFilepath + + "* Xerces signalled: \"" + xerces_msg + "\""; + + XMLString::release(&xerces_msg); +} + +void DataReader::warning(const SAXParseException& e) +{ + char* xerces_msg = NULL; + + xerces_msg = XMLString::transcode(e.getMessage()); + + mBuildErrorFlag = amis::PARSE_ERROR; + mBuildErrorMsg = "Warning while processing *" + mFilepath + + "* Xerces signalled: \"" + xerces_msg + "\""; + + XMLString::release(&xerces_msg); +} + +UiItem* DataReader::findMostRecentUiItem(UiItemType itemType) +{ + UiItem* p_item = NULL; + + for (int i=mUiItems.size()-1; i>=0; i--) + { + if (mUiItems[i]->getUiItemType() == itemType) + { + p_item = mUiItems[i]; + break; + } + } + + return p_item; +} + + +} \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUiDataReader.h =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUiDataReader.h (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AccessibleUiDataReader.h 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,113 @@ +/* +AmisGtkGuiExe: AMIS executable module and primary UI +Copyright (C) 2004 DAISY for All Project + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef ACCESSIBLEUIDATAREADER_H +#define ACCESSIBLEUIDATAREADER_H + +//SYSTEM INCLUDES +#include <string> +#include <vector> + +//XERCES INCLUDES +#include <xercesc/sax2/DefaultHandler.hpp> + +#include "DataTree.h" +#include "UiItem.h" + + +#include "../AmisCore/include/Error.h" + +//NAMESPACES +XERCES_CPP_NAMESPACE_USE + +XERCES_CPP_NAMESPACE_BEGIN +class Attributes; +XERCES_CPP_NAMESPACE_END + +using namespace std; + + +namespace AccessibleUi +{ +class DataReader: public DefaultHandler +{ +public: + //!constructor + DataReader(); + + //!destructor + ~DataReader(); + + //MEMBER FUNCTIONS + //!set the file to be processed + amis::Error readFile(string, DataTree*); + + //Xerces SAX methods + //!start tag of an element + void startElement(const XMLCh* const, const XMLCh* const, const XMLCh* const, + const Attributes&); + //!end tag of an element + void endElement(const XMLCh* const, const XMLCh* const, const XMLCh* const); + //!character data + void characters(const XMLCh *const, const unsigned int); + //!parse fatal error + void fatalError(const SAXParseException&); + //!parse warning + void warning(const SAXParseException&); + //!parse error (non-fatal) + void error(const SAXParseException&); + + string getIniFilePath(); + void setAppPath(string appPath); + +private: + UiItem* findMostRecentUiItem(UiItemType); + + //MEMBER VARIABLES + DataTree* mpData; + + vector <UiItem*> mUiItems; + + string mFilepath; + + string mAppPath; + string mIniFilePath; + + Label* mpRecentLabel; + Switch* mpRecentSwitch; + amis::TextNode* mpRecentTextNode; + Prompt* mpRecentPrompt; + + //!build error + amis::ErrorCode mBuildErrorFlag; + //!build error message + string mBuildErrorMsg; + + bool mbFlag_GetChars; + wstring mCollectedText; + + LabelList* mpRecentLabelList; + + bool mbFlag_ProcessingGeneralPrompts; + bool mbFlag_ProcessingPromptItemRefs; + +}; + +}//end namespace AccessibleUi +#endif \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.cpp (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.cpp 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,154 @@ +#include "Action.h" +#include <fstream> + +namespace AccessibleUi +{ +Action::Action() +{ + this->setUiItemType(ACTION); + mImages.empty(); + mAccelerator = NULL; + mMnemonic = NULL; +} +Action::~Action() +{ + ImageNode* p_image = NULL; + for (int i=mImages.size()-1; i>=0; i--) + { + p_image = mImages[i]; + mImages.pop_back(); + if (p_image != NULL) + delete p_image; + + p_image = NULL; + } + + +} +AccessibleUi::ImageNode* Action::getImage(ImageType type) +{ + ImageNode* p_node = NULL; + + for (int i=0; i<mImages.size(); i++) + { + if (mImages[i]->getImageType() == type) + { + p_node = mImages[i]; + break; + } + } + + return p_node; +} + +std::string Action::getWidgetCategories() +{ + return mWidgetCategories; +} +Label* Action::getKeyboardAccelerator() +{ + return mAccelerator; +} +Label* Action::getMnemonic() +{ + return mMnemonic; +} + +void Action::addImage(AccessibleUi::ImageNode* pNode) +{ + mImages.push_back(pNode); +} + +void Action::setWidgetCategories(std::string widgetCategories) +{ + this->mWidgetCategories.assign(widgetCategories); +} +void Action::setKeyboardAccelerator(Label* accelerator) +{ + this->mAccelerator = accelerator; +} +void Action::setMnemonic(Label* mnemonic) +{ + this->mMnemonic = mnemonic; +} + +void Action::setCondition(std::string rule) +{ + mCondition.assign(rule); +} + +std::string Action::getCondition() +{ + return mCondition; +} + +void Action::testPrint(std::string outfile, int numTabs) +{ + fstream out; + out.open(outfile.c_str(), ios::app | ios::out); + + int i=0; + int j=0; + + for (i=0; i<numTabs; i++){out<<"\t";} + out<<"Action"<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"id = "<<this->getId()<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"mfc id = "<<this->getMfcId()<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"widget = "<<this->mWidgetCategories<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"accelerator = "<<this->mAccelerator<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"condition = "<<mCondition<<endl; + + for (i=0; i<numTabs+1; i++){out<<"\t";} + out<<"Images"<<endl; + + for (i=0; i<mImages.size(); i++) + { + for (j=0; j<numTabs+2; j++){out<<"\t";} + out<<"src = "<<mImages[i]->getSrc()<<endl; + + for (j=0; j<numTabs+2; j++){out<<"\t";} + out<<"type = "; + + if (mImages[i]->getImageType() == SMALL_ICON) + { + out<<"small icon"<<endl; + } + else + { + out<<"large icon"<<endl; + } + } + out.close(); + + Label* p_label = NULL; + p_label = this->getCaption(); + if (p_label!=NULL) + { + p_label->testPrint(outfile, numTabs+1); + } + + p_label = NULL; + p_label = this->getDescription(); + if (p_label != NULL) + { + p_label->testPrint(outfile, numTabs+1); + } + + LabelList* p_list = NULL; + p_list = this->getLabelList(); + if (p_list != NULL) + p_list->testPrint(outfile, numTabs + 1); + +} + +} //end namespace AccessibleUi \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.h =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.h (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/Action.h 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,50 @@ +#ifndef ACTION_H +#define ACTION_H + +#include "UiMediaTypes.h" +#include "UiItem.h" + +namespace AccessibleUi +{ +class Action : public UiItem +{ +public: + Action(); + ~Action(); + AccessibleUi::ImageNode* getImage(ImageType); + + std::string getWidgetCategories(); + + Label* getMnemonic(); + Label* getKeyboardAccelerator(); + + std::string getCondition(); + + + void testPrint(std::string, int); + +protected: + void addImage(AccessibleUi::ImageNode*); + void setWidgetCategories(std::string); + + void setKeyboardAccelerator(Label*); + void setMnemonic(Label*); + + void setCondition(std::string); + +private: + std::vector<AccessibleUi::ImageNode*> mImages; + std::string mWidgetCategories; + + Label* mAccelerator; + Label* mMnemonic; + + std::string mCondition; + + + friend class DataReader; + +}; + +} +#endif \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.cpp (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.cpp 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,138 @@ +#include "AudioPrompt.h" + + +//************ +// audio prompt component +//************* +AudioPromptComponent::AudioPromptComponent() +{ + mpMedia = NULL; +} + +AudioPromptComponent::~AudioPromptComponent() +{ + if (mpMedia != NULL) + { + delete mpMedia; + } + + this->mRuntimeValue.clear(); + this->mTextAlternative.clear(); + this->mRuntimeValue.clear(); +} + + + +//************ +// audio prompt +//************* +AudioPrompt::AudioPrompt() +{ + mStringResourceID = -1; +} + +AudioPrompt::~AudioPrompt() +{ + int sz_seq = mSequence.size(); + amis::MediaNode* p_media = NULL; + int i; + + AudioPromptComponent* p_pc = NULL; + + for (i = sz_seq -1; i >=0; i--) + { + p_pc = mSequence[i]; + + mSequence.pop_back(); + + delete p_pc; + } + + this->mName.empty(); + this->mSequence.clear(); +} + +//************ +// audio prompt collection +//************* +AudioPromptCol* AudioPromptCol::pinstance = 0; + +AudioPromptCol* AudioPromptCol::Instance() +{ + if (pinstance == 0) + { + pinstance = new AudioPromptCol; + } + + return pinstance; +} + +void AudioPromptCol::DestroyInstance() +{ + delete pinstance; +} + +AudioPromptCol::AudioPromptCol() +{ +} + +AudioPromptCol::~AudioPromptCol() +{ + cleanUpVector(); + +} + +void AudioPromptCol::clearAll() +{ + cleanUpVector(); +} + +void AudioPromptCol::cleanUpVector() +{ + int sz = mPrompts.size(); + + int i; + + AudioPrompt* p_prompt = NULL; + + for (i = sz -1; i >=0; i--) + { + p_prompt = mPrompts[i]; + + mPrompts.pop_back(); + + delete p_prompt; + + } +} + +void AudioPromptCol::addPrompt(AudioPrompt* pPrompt) +{ + mPrompts.push_back(pPrompt); +} + +AudioPrompt* AudioPromptCol::getPrompt(string promptName) +{ + //search for the macro in the collection + unsigned int i; + bool b_found = false; + + for (i=0; i<mPrompts.size(); i++) + { + if (mPrompts[i]->mName.compare(promptName) == 0) + { + b_found = true; + break; + } + } + + if (b_found == false) + { + return NULL; + } + else + { + return mPrompts[i]; + } + +} \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.h =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.h (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPrompt.h 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,95 @@ +#ifndef AUDIOPROMPT_H +#define AUDIOPROMPT_H + +#include <string> + +#include "../AmisCore/include/Media.h" + +//!prompt variable structure +/*! + A variable has three properties, a name, a source function, and + a runtime value, like "yellow" or "c:\file" +*/ + +class AudioPromptComponent +{ +public: + AudioPromptComponent(); + ~AudioPromptComponent(); + //!is this a variable? + bool mbIsVar; + //!name of the variable + std::string mVarName; + //!value of the variable as given by the source function + std::wstring mRuntimeValue; + //!a media object (if it's not a variable) + amis::MediaNode* mpMedia; + // Text alternative to the audio clip: can be used for TTS or braille. + std::wstring mTextAlternative; + + +}; + +//! prompt structure +/*! + a prompt has a name (like "dialog_intro"), a list of variables (described above), + and a sequence of items to be played. + \n\n + it could also just reference a single audio clip. +*/ +class AudioPrompt +{ +public: + AudioPrompt(); + ~AudioPrompt(); + + //!name of the prompt + std::string mName; + + int mStringResourceID; + + //!list of all actions + vector<AudioPromptComponent*> mSequence; + +}; + +//collection of audio prompts +class AudioPromptCol +{ +protected: + AudioPromptCol(); + +public: + static AudioPromptCol* Instance(); + void DestroyInstance(); + ~AudioPromptCol(); + + //!return a prompt based on its name + AudioPrompt* getPrompt(string); + + //!add a prompt to the collection + void addPrompt(AudioPrompt*); + + //!clear the collection + void clearAll(); + +public: + //!the source file path for the audio prompts XML file + std::string mFilePath; + +private: + //!clean up the collection of prompts + void cleanUpVector(); + + +private: + //!the collection of prompts + vector<AudioPrompt*> mPrompts; + +private: + static AudioPromptCol* pinstance; + + +}; + +#endif \ No newline at end of file Added: branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPromptReader.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPromptReader.cpp (rev 0) +++ branches/amis3/AmisGuiMFC2/AmisSelfVoicing/AccessibleUI/AudioPromptReader.cpp 2007-10-14 13:34:13 UTC (rev 2197) @@ -0,0 +1,328 @@ +/* +AmisGuiMFC: AMIS executable module and primary UI +Copyright (C) 2004 DAISY for All Project + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/*! +This module was adapted to read audio prompts that are either a single clip +or made up of a sequence of clips and TTS renderings of variables +*/ + +//SYSTEM INCLUDES +#include <string> +#include <vector> + +#include "afxpriv.h" + +//PROJECT INCLUDES +#include <xercesc/util/XMLString.hpp> +#include <xercesc/sax2/Attributes.hpp> +#include <xercesc/sax/SAXParseException.hpp> +#include <xercesc/sax/SAXException.hpp> +#include <xercesc/sax/HandlerBase.hpp> + +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/util/TransService.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/XMLReaderFactory.hpp> + +//LOCAL INCLUDES +#include "AudioPromptReader.h" + +using namespace std; + + +AudioPromptReader::AudioPromptReader() +{ + +} + +AudioPromptReader::~AudioPromptReader() +{ + +} + + +void AudioPromptReader::loadFile(string filepath) +{ + const char* cp_file = NULL; + char* xerces_msg = NULL; + SAX2XMLReader* parser = NULL; + + + cp_file = filepath.c_str(); + + //clear any existing data + AudioPromptCol::Instance()->clearAll(); + + AudioPromptCol::Instance()->mFilePath = filepath; + + //try-catch block for Xerces platform utilities + try + { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) + { + xerces_msg = XMLString::transcode(toCatch.getMessage()); //DANIEL MEMORY LEAK VERIFIED + // cout<<"Xerces said: "<<xerces_msg<<endl; + XMLString::release(&xerces_msg); //DANIEL MEMORY LEAK VERIFIED + return; + } + + //assuming we've made it this far, create a new parser + parser = XMLReaderFactory::createXMLReader(); + + //set these parser features to turn off DTD loading and validation + parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false); + parser->setFeature(XMLUni::fgSAX2CoreValidation, false); + + + //try-catch block for Xerces parsing + try + { + parser->setContentHandler(this); + parser->setErrorHandler(this); + //parser begins fileparse. expect SAX Events soon. + parser->parse(cp_file); + } + catch (const XMLException& toCatch) + { + xerces_msg = XMLString::transcode(toCatch.getMessage()); //DANIEL MEMORY LEAK VERIFIED + //cout<<"Xerces said: "<<xerces_msg<<endl; + XMLString::release(&xerces_msg); //DANIEL MEMORY LEAK VERIFIED + //terminate the platform utilities + delete parser; + XMLPlatformUtils::Terminate(); + return; + } + + //we're done with the parser so delete it and terminate the XML platform utilities + delete parser; + XMLPlatformUtils::Terminate(); +} + +//-------------------------------------------------- +//! (SAX Event) analyze the element type and build a gui +//-------------------------------------------------- +void AudioPromptReader::startElement(const XMLCh* const uri, + const XMLCh* const localname, + const XMLCh* const qname, + const Attributes& attributes) +{ + + USES_CONVERSION; + + //local variables + char* element_name = NULL; + string tmp_string; + + //get the element name as a string + element_name = XMLString::transcode(qname); //DANIEL MEMORY LEAK VERIFIED + + if (strcmp(element_name, "prompt") == 0) + { + mpCurrentPrompt = new AudioPrompt(); + + XMLCh* txt_NAME = XMLString::transcode("name"); //DANIEL MEMORY LEAK VERIFIED + char* name = XMLString::transcode(attributes.getValue(txt_NAME)); //DANIEL MEMORY LEAK VERIFIED + XMLString::release(&txt_NAME); //DANIEL MEMORY LEAK VERIFIED + + mpCurrentPrompt->mName.assign(name); + XMLString::release(&name); //DANIEL MEMORY LEAK VERIFIED + } + + else if(strcmp(element_name, "var")==0) + { + AudioPromptComponent* p_prompt_var = NULL; + p_prompt_var = new AudioPromptComponent; + + + XMLCh* txt_NAME = XMLString::transcode("name"); //DANIEL MEMORY LEAK VERIFIED + char* name = XMLString::transcode(attributes.getValue(txt_NAME)); //DANIEL MEMORY LEAK VERIFIED + XMLString::release(&txt_NAME); //DANIEL MEMORY LEAK VERIFIED + + p_prompt_var->mVarName.assign(name); + XMLString::release(&name); //DANIEL MEMORY LEAK VERIFIED + + p_prompt_var->mRuntimeValue = _T(""); + p_prompt_var->mbIsVar = true; + + p_prompt_var->mTextAlternative = _T(""); + + mpCurrentPrompt->mSequence.push_back(p_prompt_var); + } + + + else if (strcmp(element_name, "audio") == 0) + { + amis::AudioNode* p_audio = NULL; + p_audio = new amis::AudioNode(); + + AudioPromptComponent* p_pc = NULL; + p_pc = new AudioPromptComponent; + + char* src = NULL; + XMLCh* txt_SRC = XMLString::transcode("src"); //DANIEL MEMORY LEAK VERIFIED + src = XMLString::transcode(attributes.getValue(txt_SRC)); //DANIEL MEMORY LEAK VERIFIED + XMLString::release(&txt_SRC); //DANIEL MEMORY LEAK VERIFIED + + char* clipBegin = NULL; + XMLCh* txt_CLIPBEGIN = XMLString::transcode("clipBegin"); //DANIEL MEMORY LEAK VERIFIED + clipBegin = XMLString::transcode(a... [truncated message content] |