MarkupApp.cpp
上传用户:hawkcdm
上传日期:2013-02-10
资源大小:411k
文件大小:9k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. // MarkupApp.cpp : Defines the class behaviors for the application.
  2. //
  3. // Markup Release 6.1 Lite
  4. // Copyright (C) 1999-2001 First Objective Software, Inc. All rights reserved
  5. // This entire notice must be retained in this source code
  6. // Redistributing this source code requires written permission
  7. // This software is provided "as is", with no warranty.
  8. // Latest fixes enhancements and documentation at www.firstobject.com
  9. #include "stdafx.h"
  10. #include "MarkupApp.h"
  11. #include "MainFrm.h"
  12. #include "ChildFrm.h"
  13. #include "MarkupDoc.h"
  14. #include "MarkupView.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMarkupApp
  22. BEGIN_MESSAGE_MAP(CMarkupApp, CWinApp)
  23. //{{AFX_MSG_MAP(CMarkupApp)
  24. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  25. ON_COMMAND(ID_APP_TEST, OnAppTest)
  26. //}}AFX_MSG_MAP
  27. // Standard file based document commands
  28. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30. // Standard print setup command
  31. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMarkupApp construction
  35. CMarkupApp::CMarkupApp()
  36. {
  37. // TODO: add construction code here,
  38. // Place all significant initialization in InitInstance
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CMarkupApp object
  42. CMarkupApp theApp;
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CMarkupApp initialization
  45. BOOL CMarkupApp::InitInstance()
  46. {
  47. // Standard initialization
  48. // If you are not using these features and wish to reduce the size
  49. //  of your final executable, you should remove from the following
  50. //  the specific initialization routines you do not need.
  51. #ifdef _AFXDLL
  52. Enable3dControls(); // Call this when using MFC in a shared DLL
  53. #else
  54. Enable3dControlsStatic(); // Call this when linking to MFC statically
  55. #endif
  56. // Change the registry key under which our settings are stored.
  57. // TODO: You should modify this string to be something appropriate
  58. // such as the name of your company or organization.
  59. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  60. LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  61. // Set app title
  62. CString csVersion, csV0, csV1;
  63. csVersion.LoadString( ID_APP_VERSION );
  64. AfxExtractSubString( csV0, csVersion, 0, ',' );
  65. AfxExtractSubString( csV1, csVersion, 1, ',' );
  66. CString csBuild;
  67. #if defined( _DEBUG )
  68. csBuild += _T(" Debug");
  69. #endif
  70. #if defined( _UNICODE )
  71. csBuild += _T(" Unicode");
  72. #endif
  73. m_csTitle.Format( _T("Markup %s.%s Lite%s"), csV0, csV1, csBuild );
  74. // Register the application's document templates.  Document templates
  75. //  serve as the connection between documents, frame windows and views.
  76. CMultiDocTemplate* pDocTemplate;
  77. pDocTemplate = new CMultiDocTemplate(
  78. IDR_MARKUPTYPE,
  79. RUNTIME_CLASS(CMarkupDoc),
  80. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  81. RUNTIME_CLASS(CMarkupView));
  82. AddDocTemplate(pDocTemplate);
  83. // create main MDI Frame window
  84. CMainFrame* pMainFrame = new CMainFrame;
  85. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  86. return FALSE;
  87. m_pMainWnd = pMainFrame;
  88. // Parse command line for standard shell commands, DDE, file open
  89. CCommandLineInfo cmdInfo;
  90. ParseCommandLine(cmdInfo);
  91. // Dispatch commands specified on the command line
  92. if (!ProcessShellCommand(cmdInfo))
  93. return FALSE;
  94. // TestMarkup();
  95. // The main window has been initialized, so show and update it.
  96. pMainFrame->ShowWindow(m_nCmdShow);
  97. pMainFrame->UpdateWindow();
  98. return TRUE;
  99. }
  100. void CMarkupApp::CreateNewDoc( CString csText, CString csTitle )
  101. {
  102. // This routine is used to open a document with the given text
  103. POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
  104. CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos);
  105. ASSERT(pTemplate != NULL);
  106. ASSERT_KINDOF(CDocTemplate, pTemplate);
  107. CMarkupDoc* pDoc = (CMarkupDoc*)pTemplate->OpenDocumentFile(NULL);
  108. pDoc->m_csText = csText;
  109. pDoc->m_doc.SetDoc( csText );
  110. pDoc->SetTitle( csTitle );
  111. pDoc->UpdateAllViews( NULL, 1 );
  112. pDoc->SetModifiedFlag( FALSE );
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CAboutDlg dialog used for App About
  116. class CAboutDlg : public CDialog
  117. {
  118. public:
  119. CAboutDlg();
  120. // Dialog Data
  121. //{{AFX_DATA(CAboutDlg)
  122. enum { IDD = IDD_ABOUTBOX };
  123. //}}AFX_DATA
  124. // ClassWizard generated virtual function overrides
  125. //{{AFX_VIRTUAL(CAboutDlg)
  126. protected:
  127. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  128. //}}AFX_VIRTUAL
  129. // Implementation
  130. protected:
  131. //{{AFX_MSG(CAboutDlg)
  132. virtual BOOL OnInitDialog();
  133. //}}AFX_MSG
  134. DECLARE_MESSAGE_MAP()
  135. };
  136. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  137. {
  138. //{{AFX_DATA_INIT(CAboutDlg)
  139. //}}AFX_DATA_INIT
  140. }
  141. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  142. {
  143. CDialog::DoDataExchange(pDX);
  144. //{{AFX_DATA_MAP(CAboutDlg)
  145. //}}AFX_DATA_MAP
  146. }
  147. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  148. //{{AFX_MSG_MAP(CAboutDlg)
  149. //}}AFX_MSG_MAP
  150. END_MESSAGE_MAP()
  151. BOOL CAboutDlg::OnInitDialog() 
  152. {
  153. CDialog::OnInitDialog();
  154. // Display build in title bar of About Box
  155. CString csTitle = _T("About ") + ((CMarkupApp*)AfxGetApp())->m_csTitle;
  156. SetWindowText(csTitle);
  157. // Display full version
  158. CString csVersion;
  159. csVersion.LoadString( ID_APP_VERSION );
  160. GetDlgItem( IDC_STATIC_VERSION )->SetWindowText( csVersion );
  161. return TRUE;
  162. }
  163. // App command to run the dialog
  164. void CMarkupApp::OnAppAbout()
  165. {
  166. CAboutDlg aboutDlg;
  167. aboutDlg.DoModal();
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CMarkup Test
  171. #include "Markup.h"
  172. void CMarkupApp::OnAppTest() 
  173. {
  174. // Add tests in here, accessible from the File->Test menu item
  175. // Test documents are loaded into cascaded documents
  176. m_pMainWnd->SendMessage( WM_COMMAND, ID_WINDOW_CASCADE, 0 );
  177. // ORDER Test
  178. //
  179. // This creates a document like one in the documentation
  180. // This is also just for demonstrating simple use of CMarkup
  181. //
  182. CMarkup xml;
  183. xml.AddElem( _T("ORDER") );
  184. xml.AddChildElem( _T("ITEM") );
  185. xml.IntoElem();
  186. xml.AddChildElem( _T("NAME"), _T("carrots") );
  187. xml.AddChildElem( _T("QTY"), _T("1") );
  188. xml.AddChildElem( _T("PRICE"), _T(".98") );
  189. xml.AddChildAttrib( _T("unit"), _T("1 lb") );
  190. xml.AddElem( _T("ITEM") );
  191. xml.AddChildElem( _T("NAME"), _T("onions") );
  192. xml.AddChildElem( _T("QTY"), _T("1") );
  193. xml.AddChildElem( _T("PRICE"), _T("1.10") );
  194. xml.AddChildAttrib( _T("unit"), _T("3 lb bag") );
  195. xml.AddChildElem( _T("SUPPLIER"), _T("Hanover") );
  196. CreateNewDoc( xml.GetDoc(), _T("ORDER") );
  197. // Create List
  198. CString csList;
  199. xml.ResetPos();
  200. xml.FindElem( _T("ORDER") );
  201. while ( xml.FindChildElem( _T("ITEM") ) )
  202. {
  203. xml.IntoElem();
  204. xml.FindChildElem( _T("NAME") );
  205. csList += xml.GetChildData() + _T("n");
  206. xml.OutOfElem();
  207. }
  208. csList += _T("And repeat last itemn");
  209. csList += xml.GetChildData();
  210. // Car Test Lite
  211. //
  212. // This adds randomly chosen attributes
  213. //
  214. srand( (unsigned)time( NULL ) );
  215. struct CarTestData { _TCHAR* szLow; _TCHAR* szUp; _TCHAR* szMix; } ct[] =
  216. {
  217. _T("up"), _T("SKY"), _T("Light"),
  218. _T("down"), _T("FLOOR"), _T("Dust"),
  219. _T("left"), _T("DOOR"), _T("Handle"),
  220. _T("right"), _T("SEAT"), _T("Gear"),
  221. _T("back"), _T("TRUNK"), _T("Tread"),
  222. _T("forward"), _T("GRILL"), _T("Motor"),
  223. _T(""), _T(""), _T("")
  224. };
  225. #define RND(n) max(0,min(rand()*n/RAND_MAX,n-1))
  226. xml.SetDoc( _T("") );
  227. xml.AddElem( _T("CAR") );
  228. xml.AddAttrib( ct[RND(6)].szLow, ct[RND(6)].szMix );
  229. for ( int nPart=0; nPart<100; ++nPart )
  230. {
  231. xml.AddChildElem( ct[RND(6)].szUp );
  232. xml.AddChildAttrib( ct[RND(6)].szLow, ct[RND(6)].szMix );
  233. }
  234. CString csCarDoc = xml.GetDoc();
  235. if ( ! xml.SetDoc( csCarDoc ) )
  236. AfxMessageBox( _T("Unable to parse Car document") );
  237. CreateNewDoc( xml.GetDoc(), _T("Lite Car") );
  238. // Depth First Traversal
  239. //
  240. // The following should result in ABCCCDB
  241. xml.SetDoc( _T("<A><B><C/><C/><C><D/></C></B><B/></A>") );
  242. CString csListOfTagNames;
  243. BOOL bFinished = FALSE;
  244. if ( xml.FindElem() )
  245. csListOfTagNames = xml.GetTagName();
  246. if ( ! xml.FindChildElem() )
  247. bFinished = TRUE;
  248. while ( ! bFinished )
  249. {
  250. // Process Element
  251. xml.IntoElem();
  252. csListOfTagNames += xml.GetTagName();
  253. // Next element (depth first)
  254. BOOL bFound = xml.FindChildElem();
  255. while ( ! bFound && ! bFinished )
  256. {
  257. if ( xml.OutOfElem() )
  258. bFound = xml.FindChildElem();
  259. else
  260. bFinished = TRUE;
  261. }
  262. }
  263. // AfxMessageBox( csListOfTagNames );
  264. }