📄 pagefirst.cpp
字号:
if (IDOK == dlg.DoModal ())
{
// If an image filename has been chosen, insert it at the
// end of an existing slideshow.
//
HTREEITEM hSlideItem = hParentItem != NULL? hParentItem: hSelectedItem;
InsertImage (hSlideItem, dlg.GetPathName ());
InsertTransition (hSlideItem);
c_Content.Expand (hSlideItem, TVE_EXPAND);
UpdateControls ();
}
}
}
}
_bstr_t CPageFirst::PrettyFormatXML (/*[in]*/ BSTR bstrInputXML)
{
// This method is used for pretty printing the XML file.
//
try
{
ISAXXMLReaderPtr pSAXXReader;
IMXWriterPtr pMXWriter;
EVAL_HR (pSAXXReader.CreateInstance ("MSXML2.SAXXMLReader.3.0"));
EVAL_HR (pMXWriter.CreateInstance ("MSXML2.MXXMLWriter.3.0"));
pMXWriter->indent = VARIANT_TRUE;
pMXWriter->standalone = VARIANT_TRUE;
ISAXContentHandlerPtr pSAXContentHandler (pMXWriter);
EVAL_HR (pSAXXReader->putContentHandler (pSAXContentHandler));
EVAL_HR (pSAXXReader->parse (bstrInputXML));
_variant_t varOutput = pMXWriter->output;
EVAL_HR (varOutput.vt == VT_BSTR? S_OK: E_INVALIDARG);
_bstr_t bstrRet (varOutput.bstrVal);
return bstrRet;
}
catch (...)
{
return "";
}
}
IXMLDOMDocumentPtr CPageFirst::BuildXML (void)
{
// This method is used to build an XML from the project.
//
IXMLDOMDocumentPtr pDocument;
try
{
EVAL_HR (pDocument.CreateInstance ("Msxml2.DOMDocument"));
_bstr_t bstrTarget ("xml");
_bstr_t bstrData ("version='1.0' encoding='ISO-8859-1'");
IXMLDOMProcessingInstructionPtr pPI;
pPI = pDocument->createProcessingInstruction (bstrTarget, bstrData);
pDocument->appendChild (pPI);
IXMLDOMElementPtr pNeroProjectElement;
pNeroProjectElement = pDocument->createElement ("nerovision-project");
pNeroProjectElement->setAttribute ("version", 1L);
pNeroProjectElement->setAttribute ("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
pNeroProjectElement->setAttribute ("xsi:noNamespaceSchemaLocation", _variant_t ("NeroVisionAPI.xsd"));
pDocument->appendChild (pNeroProjectElement);
// Get the project type string directly from the project type
// combobox.
//
int iProjectTypeCurSel = c_ProjectType.GetCurSel ();
ASSERT (iProjectTypeCurSel != -1);
CString sProjectType;
c_ProjectType.GetLBText (iProjectTypeCurSel, sProjectType);
// Insert a project type tag with a fixed PAL encoding.
//
IXMLDOMElementPtr pProjectType;
pProjectType = pDocument->createElement ((LPCSTR) sProjectType);
pProjectType->setAttribute ("encoding", "PAL");
pNeroProjectElement->appendChild (pProjectType);
// Insert a hardcoded label.
//
IXMLDOMElementPtr pLabel;
pLabel = pDocument->createElement ("label");
pLabel->put_text (_bstr_t ("This is a label!"));
pProjectType->appendChild (pLabel);
// Start the content tag...
//
IXMLDOMElementPtr pContent;
pContent = pDocument->createElement ("content");
pProjectType->appendChild (pContent);
int iVideoitemID = 1;
for (HTREEITEM hChild = c_Content.GetChildItem (NULL);
hChild != NULL;
hChild = c_Content.GetNextSiblingItem (hChild))
{
if (CONTENTTYPE::VIDEOTITLE == c_Content.GetItemData (hChild))
{
// This is a video. Add videotitle tag with a name attribute
// whose value is the tree item caption.
//
IXMLDOMElementPtr pVideoTitle;
pVideoTitle = pDocument->createElement ("videotitle");
pVideoTitle->setAttribute ("name", (LPCSTR) c_Content.GetItemText (hChild));
CString sID;
sID.Format ("t%d", iVideoitemID++);
pVideoTitle->setAttribute ("id", (LPCSTR) sID);
pContent->appendChild (pVideoTitle);
HTREEITEM hPathItem = c_Content.GetChildItem (hChild);
ASSERT (hPathItem != NULL);
if (hPathItem != NULL)
{
IXMLDOMElementPtr pVideo;
pVideo = pDocument->createElement ("video");
pVideo->setAttribute ("src", (LPCSTR) c_Content.GetItemText (hPathItem));
pVideoTitle->appendChild (pVideo);
}
}
else
{
// This is a slide show. Add a slideshow tag with a name
// attribute whose value is the tree item caption.
//
IXMLDOMElementPtr pSlideshowTitle;
pSlideshowTitle = pDocument->createElement ("slideshow");
pSlideshowTitle->setAttribute ("name", (LPCSTR) c_Content.GetItemText (hChild));
pContent->appendChild (pSlideshowTitle);
// Now, iterate the children and add transitions and images.
//
for (HTREEITEM hSlideChild = c_Content.GetChildItem (hChild);
hSlideChild != NULL;
hSlideChild = c_Content.GetNextSiblingItem (hSlideChild))
{
TRANSITION transition;
transition = (TRANSITION) c_Content.GetItemData (hSlideChild);
if (transition != TRANSITION::INVALID)
{
// This is a transition. Get its name from the
// combobox. We have set the values so that they
// are exactly the ones as required by the XML
// format. If transition is TRANSITION::NONE,
// this means <none> and we should skip it.
//
if (transition != TRANSITION::NONE)
{
CString sTransitionName;
c_TransitionType.GetLBText ((int) transition, sTransitionName);
IXMLDOMElementPtr pTransition;
pTransition = pDocument->createElement ("transition");
pTransition->setAttribute ("type", (LPCSTR) sTransitionName);
pSlideshowTitle->appendChild (pTransition);
}
}
else
{
// This is an image path.
//
IXMLDOMElementPtr pImage;
pImage = pDocument->createElement ("image");
pImage->setAttribute ("src", (LPCSTR) c_Content.GetItemText (hSlideChild));
pImage->setAttribute ("duration", "5");
pSlideshowTitle->appendChild (pImage);
}
}
}
}
IXMLDOMElementPtr pMenu;
pMenu = pDocument->createElement ("menu");
pMenu->setAttribute ("default-thumbnail", "FirstNonEmptyFrame");
pProjectType->appendChild (pMenu);
IXMLDOMElementPtr pDefaultTemplate;
pDefaultTemplate = pDocument->createElement ("default-template");
pDefaultTemplate->setAttribute ("id", "templ1");
pDefaultTemplate->setAttribute ("name", "Island");
pMenu->appendChild (pDefaultTemplate);
IXMLDOMElementPtr pMainMenu;
pMainMenu = pDocument->createElement ("main-menu");
pMenu->appendChild (pMainMenu);
for (int i = 1; i < iVideoitemID; i ++)
{
IXMLDOMElementPtr pChapterMenu;
pChapterMenu = pDocument->createElement ("chapter-menu");
CString sID;
sID.Format ("t%d", i);
pChapterMenu->setAttribute ("title-id", (LPCSTR) sID);
pMenu->appendChild (pChapterMenu);
}
}
catch (...)
{
// If an exception is caught, release the unfinished document.
//
pDocument = NULL;
}
return pDocument;
}
void CPageFirst::OnBeginlabeleditContent(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// Allow label editing on the first level only! This means editing is
// allowed for video and slideshow item names only. Return TRUE to
// disable editing.
//
*pResult = c_Content.GetParentItem (pTVDispInfo->item.hItem) != NULL;
}
void CPageFirst::ParseXMLDocument (const IXMLDOMDocumentPtr pDocument)
{
// First, clear the treectrl.
//
c_Content.DeleteAllItems ();
// Loop through all the nodes, look for elements.
//
for (IXMLDOMNodePtr pNode = pDocument->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
// If node is an element, the interface pointer will be non-NULL.
//
if (pElement != NULL)
{
// Check to see if the tag name is what we are looking for.
//
if (0 == wcscmp ((BSTR) pElement->tagName, L"nerovision-project"))
{
ParseNeroVisionProject (pElement);
// Once the project tag is parsed, we need parse no more.
//
break;
}
}
}
}
void CPageFirst::ParseNeroVisionProject (const IXMLDOMElementPtr pProject)
{
// Ok, we are now looking for the project type (vcd, svcd or dvd).
//
for (IXMLDOMNodePtr pNode = pProject->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
if (pElement != NULL)
{
USES_CONVERSION;
_bstr_t tagName = pElement->tagName;
LPCSTR psTagName = W2CA (tagName);
// Instead of hardcoding the strings, we will now see if the
// tag name matches any of the strings in the project type
// combobox. We could use CComboBox::FindString but this
// method uses case insensitive search and we need it to be
// case sensitive.
//
for (int i = c_ProjectType.GetCount () - 1; i >= 0; i --)
{
CString sProjectType;
c_ProjectType.GetLBText (i, sProjectType);
if (0 == strcmp (psTagName, sProjectType))
{
c_ProjectType.SetCurSel (i);
break;
}
}
// Make sure the appropriate project type was found!
//
EVAL_HR (i >= 0? S_OK: E_FAIL);
// If the subproject tag was found, parse its inner tags.
//
ParseSubproject (pElement);
// Then break as only one subproject is supported.
//
break;
}
}
}
void CPageFirst::ParseSubproject (const IXMLDOMElementPtr pSubProject)
{
// Now we are looking for the label and content tags. Actually, we
// don't care about the label as we don't have facility to neither
// display nor modify it. So, content tag is all we want. We also
// don't care about the encoding attribute as we don't use it. It is
// always PAL.
//
for (IXMLDOMNodePtr pNode = pSubProject->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
if (pElement != NULL)
{
if (0 == wcscmp ((BSTR) pElement->tagName, L"content"))
{
// Once the content tag is found, parse it, then break as
// only one content tag is allowed.
//
ParseContent (pElement);
break;
}
}
}
}
void CPageFirst::ParseContent (const IXMLDOMElementPtr pContent)
{
// Here we want videotitle and slideshow tags. Any number of these
// can appear in any order.
//
for (IXMLDOMNodePtr pNode = pContent->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
if (pElement != NULL)
{
if (0 == wcscmp ((BSTR) pElement->tagName, L"videotitle"))
{
ParseVideotitle (pElement);
}
else if (0 == wcscmp ((BSTR) pElement->tagName, L"slideshow"))
{
ParseSlideshow (pElement);
}
}
}
}
void CPageFirst::ParseVideotitle (const IXMLDOMElementPtr pVideotitle)
{
// Videotitle has a mandatory attribute "name". That is what we are
// after. A sub-tag "video" is also of interest to us.
//
IXMLDOMAttributePtr pNameAttr = pVideotitle->attributes->getNamedItem ("name");
if (pNameAttr != NULL)
{
// Look for video tag.
//
for (IXMLDOMNodePtr pNode = pVideotitle->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
if (pElement != NULL)
{
if (0 == wcscmp ((BSTR) pElement->tagName, L"video"))
{
// Video tag is found. Take its "src" attribute.
//
IXMLDOMAttributePtr pSrcAttr = pElement->attributes->getNamedItem ("src");
if (pSrcAttr != NULL)
{
// Once we have both name and src attributes,
// insert the video to the project.
//
USES_CONVERSION;
_bstr_t bstrName (pNameAttr->value);
_bstr_t bstrPath (pSrcAttr->value);
InsertVideo (W2CA (bstrName), W2CA (bstrPath));
// Then break. Only one video tag is allowed per
// videotitle tag.
//
break;
}
}
}
}
}
}
void CPageFirst::ParseSlideshow (const IXMLDOMElementPtr pSlideshow)
{
// Slideshow has a mandatory attribute "name".
//
IXMLDOMAttributePtr pNameAttr = pSlideshow->attributes->getNamedItem ("name");
if (pNameAttr != NULL)
{
// If "name" attribute is found, let's insert a slideshow into the/
// project.
//
USES_CONVERSION;
_bstr_t bstrName = pNameAttr->value;
HTREEITEM hSlideItem = InsertSlideshow (W2CA (bstrName));
// Look for transition and image tags.
//
for (IXMLDOMNodePtr pNode = pSlideshow->firstChild;
pNode != NULL;
pNode = pNode->nextSibling)
{
IXMLDOMElementPtr pElement (pNode);
if (pElement != NULL)
{
if (0 == wcscmp ((BSTR) pElement->tagName, L"transition"))
{
// A transition tag must have a "type" attribute.
//
IXMLDOMAttributePtr pTypeAttr = pElement->attributes->getNamedItem ("type");
if (pTypeAttr != NULL)
{
_bstr_t bstrTransitionType (pTypeAttr->value);
// Instead of hardcoding the strings, we will now see if the
// type attribute matches any of the strings in the transition type
// combobox.
//
for (int i = c_TransitionType.GetCount () - 1; i >= 0; i --)
{
CString sTransitionType;
c_TransitionType.GetLBText (i, sTransitionType);
if (0 == strcmp (W2CA (bstrTransitionType), sTransitionType))
{
// Once the transition type was found in
// the combobox, insert it into the
// project.
//
InsertTransition (hSlideItem, (TRANSITION) i);
break;
}
}
// Make sure the appropriate transition type was
// found!
//
EVAL_HR (i >= 0? S_OK: E_FAIL);
}
}
else if (0 == wcscmp ((BSTR) pElement->tagName, L"image"))
{
// When image tag is found, look for its "src"
// attribute.
//
IXMLDOMAttributePtr pSrcAttr = pElement->attributes->getNamedItem ("src");
if (pSrcAttr != NULL)
{
// When found, insert the image into the project.
//
_bstr_t bstrImagePath (pSrcAttr->value);
InsertImage (hSlideItem, W2CA (bstrImagePath));
}
}
}
}
// When all is parsed, expand the tree item.
//
c_Content.Expand (hSlideItem, TVE_EXPAND);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -