CommandBarsDesignerDoc.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // CommandBarsDesignerDoc.cpp : implementation of the CCommandBarsDesignerDoc class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "CommandBarsDesigner.h"
  22. #include "CommandBarsDesignerDoc.h"
  23. #include "CommandBarsDesignerView.h"
  24. #include "EmbeddedFrame.h"
  25. #include "MainFrm.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. const UINT WM_FILEDATA_RENDER = RegisterWindowMessage(_T("XCB File Data Render"));
  32. const UINT m_cfFormat = RegisterClipboardFormat(_T("XCB File Data"));
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CCommandBarsDesignerDoc
  35. IMPLEMENT_DYNCREATE(CCommandBarsDesignerDoc, CDocument)
  36. BEGIN_MESSAGE_MAP(CCommandBarsDesignerDoc, CDocument)
  37. //{{AFX_MSG_MAP(CCommandBarsDesignerDoc)
  38. // NOTE - the ClassWizard will add and remove mapping macros here.
  39. //    DO NOT EDIT what you see in these blocks of generated code!
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. BEGIN_DISPATCH_MAP(CCommandBarsDesignerDoc, CDocument)
  43. //{{AFX_DISPATCH_MAP(CCommandBarsDesignerDoc)
  44. DISP_FUNCTION(CCommandBarsDesignerDoc, "OnEdit", OnEdit, VT_BOOL, VTS_HANDLE)
  45. //}}AFX_DISPATCH_MAP
  46. END_DISPATCH_MAP()
  47. // Note: we add support for IID_ICommandBarsDesigner to support typesafe binding
  48. //  from VBA.  This IID must match the GUID that is attached to the
  49. //  dispinterface in the .ODL file.
  50. // {157FA069-D75C-4E71-A537-7C86F65FB7E9}
  51. static const IID IID_ICommandBarsDesigner =
  52. { 0x157fa069, 0xd75c, 0x4e71, { 0xa5, 0x37, 0x7c, 0x86, 0xf6, 0x5f, 0xb7, 0xe9 } };
  53. BEGIN_INTERFACE_MAP(CCommandBarsDesignerDoc, CDocument)
  54. INTERFACE_PART(CCommandBarsDesignerDoc, IID_ICommandBarsDesigner, Dispatch)
  55. END_INTERFACE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CCommandBarsDesignerDoc construction/destruction
  58. CCommandBarsDesignerDoc::CCommandBarsDesignerDoc()
  59. {
  60. m_hwndEdit = 0;
  61. EnableAutomation();
  62. AfxOleLockApp();
  63. }
  64. CCommandBarsDesignerDoc::~CCommandBarsDesignerDoc()
  65. {
  66. AfxOleUnlockApp();
  67. }
  68. BOOL CCommandBarsDesignerDoc::OnNewDocument()
  69. {
  70. if (!CDocument::OnNewDocument())
  71. return FALSE;
  72. // TODO: add reinitialization code here
  73. // (SDI documents will reuse this document)
  74. return TRUE;
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CCommandBarsDesignerDoc serialization
  78. void CCommandBarsDesignerDoc::Serialize(CArchive& ar)
  79. {
  80. POSITION pos = GetFirstViewPosition();
  81. if (pos)
  82. {
  83. CCommandBarsDesignerView* pView = (CCommandBarsDesignerView*)GetNextView(pos);
  84. ASSERT(pView);
  85. pView->Serialize(ar);
  86. }
  87. if (ar.IsStoring())
  88. {
  89. // TODO: add storing code here
  90. }
  91. else
  92. {
  93. // TODO: add loading code here
  94. }
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CCommandBarsDesignerDoc diagnostics
  98. #ifdef _DEBUG
  99. void CCommandBarsDesignerDoc::AssertValid() const
  100. {
  101. CDocument::AssertValid();
  102. }
  103. void CCommandBarsDesignerDoc::Dump(CDumpContext& dc) const
  104. {
  105. CDocument::Dump(dc);
  106. }
  107. #endif //_DEBUG
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CCommandBarsDesignerDoc commands
  110. BOOL CCommandBarsDesignerDoc::OnEdit(HWND hWnd)
  111. {
  112. ASSERT(m_bEmbedded);
  113. m_hwndEdit = hWnd;
  114. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  115. pMainFrame->ShowWindow(SW_SHOW);
  116. pMainFrame->UpdateWindow();
  117. POSITION pos = GetFirstViewPosition();
  118. CCommandBarsDesignerView* pView = (CCommandBarsDesignerView*)GetNextView(pos);
  119. pView->GetParent()->ShowWindow(SW_SHOWMAXIMIZED);
  120. if (!OpenClipboard(hWnd))
  121. return FALSE;
  122. if (::IsClipboardFormatAvailable(m_cfFormat))
  123. {
  124. HGLOBAL hGlobal = GetClipboardData (m_cfFormat);
  125. LPVOID pData = GlobalLock(hGlobal);
  126. CMemFile file((BYTE*)pData + sizeof(DWORD), *(DWORD*)pData);
  127. CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);
  128. Serialize(ar);
  129. GlobalUnlock(hGlobal);
  130. }
  131. else
  132. {
  133. pView->GetEmbeddedFrame()->Clear();
  134. }
  135. ::CloseClipboard();
  136. pView->OnInitialUpdate();
  137. pMainFrame->RefreshPanes(TRUE);
  138. return TRUE;
  139. }
  140. BOOL CCommandBarsDesignerDoc::DoFileSave()
  141. {
  142. if (m_bEmbedded)
  143. {
  144. ASSERT(m_hwndEdit);
  145. m_bModified = FALSE;
  146. CMemFile file;
  147. CArchive ar(&file, CArchive::store);
  148. Serialize(ar);
  149. ar.Flush();
  150. DWORD dwSize = (DWORD)file.GetPosition();
  151. BYTE* pFileData = file.Detach();
  152. HGLOBAL hDesignerData = GlobalAlloc(GMEM_FIXED, dwSize + sizeof(DWORD));
  153. LPVOID pData =  GlobalLock(hDesignerData);
  154. *((DWORD*)pData) = dwSize;
  155. memcpy((BYTE*)pData + sizeof(DWORD), pFileData, dwSize);
  156. GlobalUnlock(hDesignerData);
  157. ar.Abort();
  158. file.Close();
  159. if (!::OpenClipboard (0))
  160. return TRUE;
  161. if (!::EmptyClipboard ())
  162. {
  163. ::CloseClipboard ();
  164. return TRUE;
  165. }
  166. UINT uFormat = RegisterClipboardFormat(_T("XCB File Data"));
  167. SetClipboardData(uFormat, hDesignerData);
  168. ::CloseClipboard();
  169. SendMessage(m_hwndEdit, WM_FILEDATA_RENDER, 0, 0);
  170. if (AfxGetMainWnd() && AfxGetMainWnd()->GetSafeHwnd())
  171. {
  172. AfxGetMainWnd()->PostMessage(WM_CLOSE);
  173. }
  174. return TRUE;
  175. }
  176. return CDocument::DoFileSave();
  177. }