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

对话框与窗口

开发平台:

Visual C++

  1. // ResourceEditorView.cpp : implementation of the CResourceEditorView 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 "ResourceEditor.h"
  22. #include "ResourceEditorDoc.h"
  23. #include "ResourceEditorView.h"
  24. #include "ChildFrm.h"
  25. #include "ResourceViewRecord.h"
  26. #include "MainFrm.h"
  27. #include "ResourceExport.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CResourceEditorView
  35. IMPLEMENT_DYNCREATE(CResourceEditorView, CXTPReportView)
  36. BEGIN_MESSAGE_MAP(CResourceEditorView, CXTPReportView)
  37. //{{AFX_MSG_MAP(CResourceEditorView)
  38. ON_WM_CREATE()
  39. //}}AFX_MSG_MAP
  40. // Standard printing commands
  41. ON_NOTIFY(XTP_NM_REPORT_VALUECHANGED, XTP_ID_REPORT_CONTROL, OnReportValueChanged)
  42. ON_NOTIFY(XTP_NM_REPORT_SELCHANGED, XTP_ID_REPORT_CONTROL, OnReportSelectionChanged)
  43. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  44. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  45. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CResourceEditorView construction/destruction
  49. CResourceEditorView::CResourceEditorView()
  50. {
  51. // TODO: add construction code here
  52. }
  53. CResourceEditorView::~CResourceEditorView()
  54. {
  55. }
  56. BOOL CResourceEditorView::PreCreateWindow(CREATESTRUCT& cs)
  57. {
  58. // TODO: Modify the Window class or styles here by modifying
  59. //  the CREATESTRUCT cs
  60. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  61. //cs.style &= ~WS_BORDER;
  62. return CXTPReportView::PreCreateWindow(cs);
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CResourceEditorView diagnostics
  66. #ifdef _DEBUG
  67. void CResourceEditorView::AssertValid() const
  68. {
  69. CXTPReportView::AssertValid();
  70. }
  71. void CResourceEditorView::Dump(CDumpContext& dc) const
  72. {
  73. CXTPReportView::Dump(dc);
  74. }
  75. CResourceEditorDoc* CResourceEditorView::GetDocument() // non-debug version is inline
  76. {
  77. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CResourceEditorDoc)));
  78. return (CResourceEditorDoc*)m_pDocument;
  79. }
  80. #endif //_DEBUG
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CResourceEditorView message handlers
  83. int CResourceEditorView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  84. {
  85. if (CXTPReportView::OnCreate(lpCreateStruct) == -1)
  86. return -1;
  87. return 0;
  88. }
  89. void CResourceEditorView::LoadXMLString(CXTPPropExchange* pPX, LPCTSTR pszPropName, CString& strValue)
  90. {
  91. #ifdef _UNICODE
  92. PX_String(pPX, pszPropName, strValue);
  93. #else
  94. BSTR bstrValue = 0;
  95. PX_Bstr(pPX, pszPropName, bstrValue, 0);
  96. ASSERT(!bstrValue || wcslen(bstrValue) < 1024);
  97. if (bstrValue)
  98. {
  99. WideCharToMultiByte(GetDocument()->m_pLanguageInfo->nCodePage, 0, bstrValue, -1, strValue.GetBuffer(1024), 1024, 0, 0);
  100. strValue.ReleaseBuffer();
  101. SysFreeString(bstrValue);
  102. }
  103. #endif
  104. CXTPPropExchangeXMLNode::PreformatString(strValue, FALSE);
  105. }
  106. void CResourceEditorView::PopulateStringResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemStrings)
  107. {
  108. CXTPReportControl& wndReport = GetReportCtrl();
  109. CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("string")));
  110. POSITION pos = ptrEnumeratorStrings->GetPosition();
  111. while (pos)
  112. {
  113. CXTPPropExchangeXMLNode* ptrSectionString = (CXTPPropExchangeXMLNode*)ptrEnumeratorStrings->GetNext(pos);
  114. CString strValue;
  115. DWORD dwId = 0;
  116. PX_DWord(ptrSectionString, _T("id"), dwId);
  117. LoadXMLString(ptrSectionString, _T("value"), strValue);
  118. CResourceViewRecord* pRecord = new CResourceViewRecord(_T("String"), resString, dwId, strValue);
  119. wndReport.GetRecords()->Add(pRecord);
  120. pRecord->m_pSection = ptrSectionString;
  121. HTREEITEM hItemString = wndResourceTree.InsertItem(GetResourceName(dwId), 6, 6, hItemStrings);
  122. wndResourceTree.SetItemData(hItemString, (DWORD_PTR)pRecord);
  123. }
  124. }
  125. void CResourceEditorView::PopulateMenuItemsResources(CXTPReportRecord* pMenuBase, CXTPReportRecord* pMenuRecord, CXTPPropExchange* pResourceMenu)
  126. {
  127. CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResourceMenu->GetEnumerator(_T("menuitem")));
  128. POSITION pos = ptrEnumeratorStrings->GetPosition();
  129. while (pos)
  130. {
  131. CXTPPropExchangeXMLNode* ptrSectionMenuItem = (CXTPPropExchangeXMLNode*)ptrEnumeratorStrings->GetNext(pos);
  132. CString strValue;
  133. DWORD dwId = 0;
  134. PX_DWord(ptrSectionMenuItem, _T("id"), dwId);
  135. LoadXMLString(ptrSectionMenuItem, _T("caption"), strValue);
  136. CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Menuitem"), resMenu, dwId, strValue);
  137. pMenuRecord->GetChilds()->Add(pRecord);
  138. pRecord->m_pSection = ptrSectionMenuItem;
  139. PopulateMenuItemsResources(pMenuBase, pRecord, ptrSectionMenuItem);
  140. }
  141. }
  142. void CResourceEditorView::PopulateDialogControlsResources(CResourceViewRecord* pDialogRecord, CXTPPropExchange* pResourceDialog)
  143. {
  144. CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResourceDialog->GetEnumerator(_T("control")));
  145. POSITION pos = ptrEnumeratorStrings->GetPosition();
  146. while (pos)
  147. {
  148. CXTPPropExchangeXMLNode* ptrSectionDialogControl = (CXTPPropExchangeXMLNode*)ptrEnumeratorStrings->GetNext(pos);
  149. CString strValue;
  150. DWORD dwId = 0;
  151. PX_DWord(ptrSectionDialogControl, _T("id"), dwId);
  152. LoadXMLString(ptrSectionDialogControl, _T("caption"), strValue);
  153. CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Control"), resDialog, dwId, strValue);
  154. pDialogRecord->GetChilds()->Add(pRecord);
  155. pRecord->m_pSection = ptrSectionDialogControl;
  156. pRecord->m_pBaseRecord = pDialogRecord;
  157. }
  158. }
  159. void CResourceEditorView::PopulateDialogResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemDialogs)
  160. {
  161. CXTPReportControl& wndReport = GetReportCtrl();
  162. CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("dialog")));
  163. POSITION pos = ptrEnumeratorStrings->GetPosition();
  164. while (pos)
  165. {
  166. CXTPPropExchangeXMLNode* ptrSectionDialog = (CXTPPropExchangeXMLNode*)ptrEnumeratorStrings->GetNext(pos);
  167. DWORD dwId = 0;
  168. CString strValue;
  169. PX_DWord(ptrSectionDialog, _T("id"), dwId);
  170. LoadXMLString(ptrSectionDialog, _T("caption"), strValue);
  171. CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Dialog"), resDialog, dwId, strValue);
  172. wndReport.GetRecords()->Add(pRecord);
  173. pRecord->m_pSection = ptrSectionDialog;
  174. HTREEITEM hItemDialog = wndResourceTree.InsertItem(GetResourceName(dwId), 3, 3, hItemDialogs);
  175. wndResourceTree.SetItemData(hItemDialog, (DWORD_PTR)pRecord);
  176. PopulateDialogControlsResources(pRecord, ptrSectionDialog);
  177. }
  178. }
  179. void CResourceEditorView::PopulateMenuResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemMenus)
  180. {
  181. CXTPReportControl& wndReport = GetReportCtrl();
  182. CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("menu")));
  183. POSITION pos = ptrEnumeratorStrings->GetPosition();
  184. while (pos)
  185. {
  186. CXTPPropExchangeXMLNode* ptrSectionMenu = (CXTPPropExchangeXMLNode*)ptrEnumeratorStrings->GetNext(pos);
  187. DWORD dwId = 0;
  188. PX_DWord(ptrSectionMenu, _T("id"), dwId);
  189. CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Menu"), resMenu, dwId, _T(""));
  190. wndReport.GetRecords()->Add(pRecord);
  191. pRecord->m_pSection = ptrSectionMenu;
  192. pRecord->SetEditable(FALSE);
  193. HTREEITEM hItemMenu = wndResourceTree.InsertItem(GetResourceName(dwId), 5, 5, hItemMenus);
  194. wndResourceTree.SetItemData(hItemMenu, (DWORD_PTR)pRecord);
  195. PopulateMenuItemsResources(pRecord, pRecord, ptrSectionMenu);
  196. }
  197. }
  198. void CResourceEditorView::PopulateResources()
  199. {
  200. CXTPReportControl& wndReport = GetReportCtrl();
  201. wndReport.GetRecords()->RemoveAll();
  202. CResourceEditorDoc* pDocument = GetDocument();
  203. CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources;
  204. CTreeCtrl& wndResourceTree = ((CChildFrame*)GetParentFrame())->m_wndResourceTree;
  205. wndResourceTree.DeleteAllItems();
  206. HTREEITEM hItemResources = wndResourceTree.InsertItem(_T("Resources"));
  207. HTREEITEM hItemStrings = wndResourceTree.InsertItem(_T("String Table"), 6, 6, hItemResources);
  208. HTREEITEM hItemMenus = wndResourceTree.InsertItem(_T("Menus"), 5, 5, hItemResources);
  209. HTREEITEM hItemDialogs = wndResourceTree.InsertItem(_T("Dialogs"), 3, 3, hItemResources);
  210. if (pResources)
  211. {
  212. CString strLanguage;
  213. PX_String(pResources, _T("Language"), strLanguage);
  214. wndReport.GetColumns()->Find(3)->SetCaption(strLanguage);
  215. PopulateStringResources(wndResourceTree, pResources, hItemStrings);
  216. PopulateMenuResources(wndResourceTree, pResources, hItemMenus);
  217. PopulateDialogResources(wndResourceTree, pResources, hItemDialogs);
  218. }
  219. wndResourceTree.Expand(hItemResources, TVE_EXPAND);
  220. wndReport.Populate();
  221. }
  222. void CResourceEditorView::OnInitialUpdate() 
  223. {
  224. CXTPReportView::OnInitialUpdate();
  225. XTP_RESOURCEMANAGER_LANGINFO* pLanguageInfo = GetDocument()->m_pLanguageInfo;
  226. ASSERT(pLanguageInfo);
  227. CXTPReportControl& wndReport = GetReportCtrl();
  228. wndReport.GetImageManager()->SetIcons(IDB_RESTREE, 0, 10, 0);
  229. wndReport.GetPaintManager()->m_treeStructureStyle = xtpReportTreeStructureDots;
  230. CXTPReportColumn* pColumn;
  231. pColumn = new CXTPReportColumn(4, _T("Resource"), 180, TRUE);
  232. pColumn->SetEditable(FALSE);
  233. wndReport.GetColumns()->Add(pColumn);
  234. wndReport.GetColumns()->GetGroupsOrder()->Add(pColumn, FALSE);
  235. pColumn->SetTreeColumn(TRUE);
  236. pColumn = new CXTPReportColumn(0, _T("Module"), 130, TRUE);
  237. pColumn->SetEditable(FALSE);
  238. wndReport.GetColumns()->Add(pColumn);
  239. wndReport.GetColumns()->GetGroupsOrder()->Add(pColumn);
  240. pColumn->SetVisible(FALSE);
  241. pColumn = new CXTPReportColumn(1, _T("ID"), 40, FALSE);
  242. pColumn->SetEditable(FALSE);
  243. wndReport.GetColumns()->Add(pColumn);
  244. pColumn = new CXTPReportColumn(2, _T("English US (Original Resources)"), 300, TRUE);
  245. pColumn->SetEditable(FALSE);
  246. wndReport.GetColumns()->Add(pColumn);
  247. pColumn = new CXTPReportColumn(3, _T("Tranlated"), 300, TRUE);
  248. pColumn->SetAlignment(pLanguageInfo->nCodePage == 1256 || pLanguageInfo->nCodePage == 1255 ? DT_RIGHT : DT_LEFT);
  249. wndReport.GetColumns()->Add(pColumn);
  250. wndReport.GetPaintManager()->SetColumnStyle(xtpReportColumnExplorer);
  251. wndReport.GetReportHeader()->AllowColumnRemove(FALSE);
  252. wndReport.AllowEdit(TRUE);
  253. wndReport.EditOnClick(FALSE);
  254. wndReport.ShowGroupBy();
  255. LOGFONT lfIcon;
  256. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  257. lfIcon.lfCharSet = pLanguageInfo->nFontCharSet;
  258. GetReportCtrl().GetPaintManager()->SetTextFont(lfIcon);
  259. PopulateResources();
  260. }
  261. void CResourceEditorView::OnReportValueChanged(NMHDR * pNotifyStruct, LRESULT * /*result*/)
  262. {
  263. XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
  264. ASSERT(pItemNotify->pItem);
  265. CResourceEditorDoc* pDocument = GetDocument();
  266. CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources;
  267. if (pItemNotify->pItem && pResources)
  268. {
  269. CResourceViewRecord* pRecord = (CResourceViewRecord*)pItemNotify->pItem->GetRecord();
  270. CXTPPropExchangeXMLNode* ptrSectionString = pRecord->m_pSection;
  271. if (ptrSectionString)
  272. {
  273. ptrSectionString->SetLoading(FALSE);
  274. CString strValue = pItemNotify->pItem->GetCaption(0);
  275. CString strSection = pRecord->m_resType == resString ? _T("value"): _T("caption");
  276. #ifdef _UNICODE
  277. CXTPPropExchangeXMLNode::PreformatString(strValue, TRUE);
  278. PX_String(ptrSectionString, strSection, strValue);
  279. #else
  280. WCHAR lpszValue[1024];
  281. lpszValue[0] = 0;
  282. MultiByteToWideChar(GetDocument()->m_pLanguageInfo->nCodePage, 0,
  283. strValue, -1, lpszValue, 1024);
  284. BSTR bstrVal = (BSTR)&lpszValue;
  285. PX_Bstr(ptrSectionString, strSection, bstrVal, NULL);
  286. #endif
  287. }
  288. }
  289. GetDocument()->SetModifiedFlag();
  290. }
  291. void CResourceEditorView::OnReportSelectionChanged(NMHDR * /*pNotifyStruct*/, LRESULT * /*result*/)
  292. {
  293. CXTPReportControl& wndReport = GetReportCtrl();
  294. CXTPReportRow* pRow = wndReport.GetFocusedRow();
  295. CResourceEditorDoc* pDocument = GetDocument();
  296. CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources;
  297. if (pRow && pRow->GetRecord() && pResources)
  298. {
  299. CResourceViewRecord* pRecord = (CResourceViewRecord*)pRow->GetRecord();
  300. if (pRecord->m_pBaseRecord) pRecord = pRecord->m_pBaseRecord;
  301. DWORD dwId = pRecord->GetId();
  302. if (pRecord->m_resType == resMenu && dwId)
  303. {
  304. ((CMainFrame*)AfxGetMainWnd())->ShowMenuPreview(pResources, dwId, pDocument->m_pLanguageInfo);
  305. }
  306. else if (pRecord->m_resType == resDialog && dwId)
  307. {
  308. ((CMainFrame*)AfxGetMainWnd())->ShowDialogPreview(pResources, dwId);
  309. }
  310. else
  311. {
  312. ((CMainFrame*)AfxGetMainWnd())->ClearPreview();
  313. }
  314. }
  315. else
  316. {
  317. ((CMainFrame*)AfxGetMainWnd())->ClearPreview();
  318. }
  319. }
  320. void CResourceEditorView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  321. {
  322. if (!bActivate)
  323. {
  324. ((CMainFrame*)AfxGetMainWnd())->ClearPreview();
  325. }
  326. CXTPReportView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  327. }