// ResourceEditorView.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ResourceEditor.h" #include "ResourceEditorDoc.h" #include "ResourceEditorView.h" #include "ChildFrm.h" #include "ResourceViewRecord.h" #include "MainFrm.h" #include "ResourceExport.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CResourceEditorView IMPLEMENT_DYNCREATE(CResourceEditorView, CXTPGridView) BEGIN_MESSAGE_MAP(CResourceEditorView, CXTPGridView) //{{AFX_MSG_MAP(CResourceEditorView) ON_WM_CREATE() //}}AFX_MSG_MAP // Standard printing commands ON_NOTIFY(XTP_NM_GRID_VALUECHANGED, XTP_ID_GRID_CONTROL, OnGridValueChanged) ON_NOTIFY(XTP_NM_GRID_SELCHANGED, XTP_ID_GRID_CONTROL, OnGridSelectionChanged) ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CResourceEditorView construction/destruction CResourceEditorView::CResourceEditorView() { // TODO: add construction code here } CResourceEditorView::~CResourceEditorView() { } BOOL CResourceEditorView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; cs.style &= ~WS_BORDER; return CXTPGridView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CResourceEditorView diagnostics #ifdef _DEBUG void CResourceEditorView::AssertValid() const { CXTPGridView::AssertValid(); } void CResourceEditorView::Dump(CDumpContext& dc) const { CXTPGridView::Dump(dc); } CResourceEditorDoc* CResourceEditorView::GetDocument() // non-debug version is inline { _ASSERTE(m_pDocument->IsKindOf(RUNTIME_CLASS(CResourceEditorDoc))); return (CResourceEditorDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CResourceEditorView message handlers int CResourceEditorView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CXTPGridView::OnCreate(lpCreateStruct) == -1) return -1; return 0; } void CResourceEditorView::LoadXMLString(CXTPPropExchange* pPX, LPCTSTR pszPropName, CString& strValue) { #ifdef _UNICODE PX_String(pPX, pszPropName, strValue); #else BSTR bstrValue = 0; PX_Bstr(pPX, pszPropName, bstrValue, 0); _ASSERTE(!bstrValue || wcslen(bstrValue) < 1024); if (bstrValue) { WideCharToMultiByte(GetDocument()->m_pLanguageInfo->nCodePage, 0, bstrValue, -1, strValue.GetBuffer(1024), 1024, 0, 0); strValue.ReleaseBuffer(); SysFreeString(bstrValue); } #endif CXTPPropExchangeXMLNode::PreformatString(strValue, FALSE); } void CResourceEditorView::PopulateStringResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemStrings) { CXTPGridControl& wndGrid = GetGridCtrl(); CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("string"))); POSITION pos = ptrEnumeratorStrings->GetPosition(); while (pos) { CXTPPropExchangeXMLNode* ptrSectionString = (CXTPPropExchangeXMLNode*) ptrEnumeratorStrings->GetNext(pos); CString strValue; DWORD dwId = 0; PX_DWord(ptrSectionString, _T("id"), dwId); LoadXMLString(ptrSectionString, _T("value"), strValue); CResourceViewRecord* pRecord = new CResourceViewRecord(_T("String"), resString, dwId, strValue); wndGrid.GetRecords()->Add(pRecord); pRecord->m_pSection = ptrSectionString; HTREEITEM hItemString = wndResourceTree.InsertItem(GetResourceName(dwId), 6, 6, hItemStrings); wndResourceTree.SetItemData(hItemString, (DWORD_PTR)pRecord); } } void CResourceEditorView::PopulateMenuItemsResources(CXTPGridRecord* pMenuBase, CXTPGridRecord* pMenuRecord, CXTPPropExchange* pResourceMenu) { CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings( pResourceMenu->GetEnumerator(_T("menuitem"))); POSITION pos = ptrEnumeratorStrings->GetPosition(); while (pos) { CXTPPropExchangeXMLNode* ptrSectionMenuItem = (CXTPPropExchangeXMLNode*) ptrEnumeratorStrings->GetNext(pos); CString strValue; DWORD dwId = 0; PX_DWord(ptrSectionMenuItem, _T("id"), dwId); LoadXMLString(ptrSectionMenuItem, _T("caption"), strValue); CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Menuitem"), resMenu, dwId, strValue); pMenuRecord->GetChilds()->Add(pRecord); pRecord->m_pSection = ptrSectionMenuItem; PopulateMenuItemsResources(pMenuBase, pRecord, ptrSectionMenuItem); } } void CResourceEditorView::PopulateDialogControlsResources(CResourceViewRecord* pDialogRecord, CXTPPropExchange* pResourceDialog) { CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings( pResourceDialog->GetEnumerator(_T("control"))); POSITION pos = ptrEnumeratorStrings->GetPosition(); while (pos) { CXTPPropExchangeXMLNode* ptrSectionDialogControl = (CXTPPropExchangeXMLNode*) ptrEnumeratorStrings->GetNext(pos); CString strValue; DWORD dwId = 0; PX_DWord(ptrSectionDialogControl, _T("id"), dwId); LoadXMLString(ptrSectionDialogControl, _T("caption"), strValue); CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Control"), resDialog, dwId, strValue); pDialogRecord->GetChilds()->Add(pRecord); pRecord->m_pSection = ptrSectionDialogControl; pRecord->m_pBaseRecord = pDialogRecord; } } void CResourceEditorView::PopulateDialogResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemDialogs) { CXTPGridControl& wndGrid = GetGridCtrl(); CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("dialog"))); POSITION pos = ptrEnumeratorStrings->GetPosition(); while (pos) { CXTPPropExchangeXMLNode* ptrSectionDialog = (CXTPPropExchangeXMLNode*) ptrEnumeratorStrings->GetNext(pos); DWORD dwId = 0; CString strValue; PX_DWord(ptrSectionDialog, _T("id"), dwId); LoadXMLString(ptrSectionDialog, _T("caption"), strValue); CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Dialog"), resDialog, dwId, strValue); wndGrid.GetRecords()->Add(pRecord); pRecord->m_pSection = ptrSectionDialog; HTREEITEM hItemDialog = wndResourceTree.InsertItem(GetResourceName(dwId), 3, 3, hItemDialogs); wndResourceTree.SetItemData(hItemDialog, (DWORD_PTR)pRecord); PopulateDialogControlsResources(pRecord, ptrSectionDialog); } } void CResourceEditorView::PopulateMenuResources(CTreeCtrl& wndResourceTree, CXTPPropExchange* pResources, HTREEITEM hItemMenus) { CXTPGridControl& wndGrid = GetGridCtrl(); CXTPPropExchangeEnumeratorPtr ptrEnumeratorStrings(pResources->GetEnumerator(_T("menu"))); POSITION pos = ptrEnumeratorStrings->GetPosition(); while (pos) { CXTPPropExchangeXMLNode* ptrSectionMenu = (CXTPPropExchangeXMLNode*) ptrEnumeratorStrings->GetNext(pos); DWORD dwId = 0; PX_DWord(ptrSectionMenu, _T("id"), dwId); CResourceViewRecord* pRecord = new CResourceViewRecord(_T("Menu"), resMenu, dwId, _T("")); wndGrid.GetRecords()->Add(pRecord); pRecord->m_pSection = ptrSectionMenu; pRecord->SetEditable(FALSE); HTREEITEM hItemMenu = wndResourceTree.InsertItem(GetResourceName(dwId), 5, 5, hItemMenus); wndResourceTree.SetItemData(hItemMenu, (DWORD_PTR)pRecord); PopulateMenuItemsResources(pRecord, pRecord, ptrSectionMenu); } } void CResourceEditorView::PopulateResources() { CXTPGridControl& wndGrid = GetGridCtrl(); wndGrid.GetRecords()->RemoveAll(); CResourceEditorDoc* pDocument = GetDocument(); CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources; CTreeCtrl& wndResourceTree = ((CChildFrame*)GetParentFrame())->m_wndResourceTree; wndResourceTree.DeleteAllItems(); HTREEITEM hItemResources = wndResourceTree.InsertItem(_T("Resources")); HTREEITEM hItemStrings = wndResourceTree.InsertItem(_T("String Table"), 6, 6, hItemResources); HTREEITEM hItemMenus = wndResourceTree.InsertItem(_T("Menus"), 5, 5, hItemResources); HTREEITEM hItemDialogs = wndResourceTree.InsertItem(_T("Dialogs"), 3, 3, hItemResources); if (pResources) { CString strLanguage; PX_String(pResources, _T("Language"), strLanguage); wndGrid.GetColumns()->Find(3)->SetCaption(strLanguage); PopulateStringResources(wndResourceTree, pResources, hItemStrings); PopulateMenuResources(wndResourceTree, pResources, hItemMenus); PopulateDialogResources(wndResourceTree, pResources, hItemDialogs); } wndResourceTree.Expand(hItemResources, TVE_EXPAND); wndGrid.Populate(); } void CResourceEditorView::OnInitialUpdate() { CXTPGridView::OnInitialUpdate(); XTP_RESOURCEMANAGER_LANGINFO* pLanguageInfo = GetDocument()->m_pLanguageInfo; _ASSERTE(pLanguageInfo); CXTPGridControl& wndGrid = GetGridCtrl(); wndGrid.GetImageManager()->SetIcons(IDB_RESTREE, 0, 10, 0); wndGrid.GetPaintManager()->m_treeStructureStyle = xtpGridTreeStructureDots; CXTPGridColumn* pColumn; pColumn = new CXTPGridColumn(4, _T("Resource"), 180, TRUE); pColumn->SetEditable(FALSE); wndGrid.GetColumns()->Add(pColumn); wndGrid.GetColumns()->GetGroupsOrder()->Add(pColumn, FALSE); pColumn->SetTreeColumn(TRUE); pColumn = new CXTPGridColumn(0, _T("Module"), 130, TRUE); pColumn->SetEditable(FALSE); wndGrid.GetColumns()->Add(pColumn); wndGrid.GetColumns()->GetGroupsOrder()->Add(pColumn); pColumn->SetVisible(FALSE); pColumn = new CXTPGridColumn(1, _T("ID"), 40, FALSE); pColumn->SetEditable(FALSE); wndGrid.GetColumns()->Add(pColumn); pColumn = new CXTPGridColumn(2, _T("English US (Original Resources)"), 300, TRUE); pColumn->SetEditable(FALSE); wndGrid.GetColumns()->Add(pColumn); pColumn = new CXTPGridColumn(3, _T("Tranlated"), 300, TRUE); pColumn->SetAlignment( pLanguageInfo->nCodePage == 1256 || pLanguageInfo->nCodePage == 1255 ? DT_RIGHT : DT_LEFT); wndGrid.GetColumns()->Add(pColumn); wndGrid.GetPaintManager()->SetColumnStyle(xtpGridColumnExplorer); wndGrid.GetGridHeader()->AllowColumnRemove(FALSE); wndGrid.AllowEdit(TRUE); wndGrid.EditOnClick(FALSE); wndGrid.ShowGroupBy(); m_bAllowPaste = FALSE; LOGFONT lfIcon; VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0)); lfIcon.lfCharSet = pLanguageInfo->nFontCharSet; GetGridCtrl().GetPaintManager()->SetTextFont(lfIcon); if (((CMainFrame*)AfxGetMainWnd())->m_nTheme == 0) CXTPGridView::SetTheme(xtpGridThemeDefault); else CXTPGridView::SetTheme(xtpGridThemeOffice2013, TRUE); PopulateResources(); } void CResourceEditorView::OnGridValueChanged(NMHDR* pNotifyStruct, LRESULT* /*result*/) { XTP_NM_GRIDRECORDITEM* pItemNotify = (XTP_NM_GRIDRECORDITEM*)pNotifyStruct; _ASSERTE(pItemNotify->pItem); CResourceEditorDoc* pDocument = GetDocument(); CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources; if (pItemNotify->pItem && pResources) { CResourceViewRecord* pRecord = DYNAMIC_DOWNCAST(CResourceViewRecord, pItemNotify->pItem->GetRecord()); if (pRecord == NULL) { return; } CXTPPropExchangeXMLNode* ptrSectionString = pRecord->m_pSection; if (ptrSectionString) { ptrSectionString->SetLoading(FALSE); CString strValue = pItemNotify->pItem->GetCaption(0); CString strSection = pRecord->m_resType == resString ? _T("value") : _T("caption"); #ifdef _UNICODE CXTPPropExchangeXMLNode::PreformatString(strValue, TRUE); PX_String(ptrSectionString, strSection, strValue); #else WCHAR lpszValue[1024]; lpszValue[0] = 0; MultiByteToWideChar(GetDocument()->m_pLanguageInfo->nCodePage, 0, strValue, -1, lpszValue, 1024); BSTR bstrVal = (BSTR)&lpszValue; PX_Bstr(ptrSectionString, strSection, bstrVal, NULL); #endif } } GetDocument()->SetModifiedFlag(); } void CResourceEditorView::OnGridSelectionChanged(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/) { CXTPGridControl& wndGrid = GetGridCtrl(); CXTPGridRow* pRow = wndGrid.GetFocusedRow(); CResourceEditorDoc* pDocument = GetDocument(); CXTPPropExchangeXMLNode* pResources = pDocument->m_pResources; if (pRow && pRow->GetRecord() && pResources) { CResourceViewRecord* pRecord = DYNAMIC_DOWNCAST(CResourceViewRecord, pRow->GetRecord()); if (pRecord == NULL) { ((CMainFrame*)AfxGetMainWnd())->ClearPreview(); return; } if (pRecord->m_pBaseRecord) pRecord = pRecord->m_pBaseRecord; DWORD dwId = pRecord->GetId(); if (pRecord->m_resType == resMenu && dwId) { ((CMainFrame*)AfxGetMainWnd()) ->ShowMenuPreview(pResources, dwId, pDocument->m_pLanguageInfo); } else if (pRecord->m_resType == resDialog && dwId) { ((CMainFrame*)AfxGetMainWnd())->ShowDialogPreview(pResources, dwId); } else { ((CMainFrame*)AfxGetMainWnd())->ClearPreview(); } } else { ((CMainFrame*)AfxGetMainWnd())->ClearPreview(); } } void CResourceEditorView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if (!bActivate) { ((CMainFrame*)AfxGetMainWnd())->ClearPreview(); } CXTPGridView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CResourceEditorView::RefreshTheme(XTPGridPaintTheme theme) { CXTPGridView::SetTheme(theme, TRUE); if (theme == xtpGridThemeDefault) { ((CChildFrame*)GetParentFrame())->m_wndResourceTree.SetTheme(xtpControlThemeDefault); ((CChildFrame*)GetParentFrame())->m_paneManager.SetTheme(xtpPaneThemeVisualStudio2005); } else { ((CChildFrame*)GetParentFrame())->m_wndResourceTree.SetTheme(xtpControlThemeOffice2013); ((CChildFrame*)GetParentFrame())->m_paneManager.SetTheme(xtpPaneThemeOffice2013); } } void CResourceEditorView::OnFilePrintPreview() { // replace the default print preview with ours! // In derived classes, implement special window handling here // Be sure to Unhook Frame Window close if hooked. // must not create this on the frame. Must outlive this function CPrintPreviewState* pState = new CPrintPreviewState; // DoPrintPreview's return value does not necessarily indicate that // Print preview succeeded or failed, but rather what actions are necessary // at this point. If DoPrintPreview returns TRUE, it means that // OnEndPrintPreview will be (or has already been) called and the // pState structure will be/has been deleted. // If DoPrintPreview returns FALSE, it means that OnEndPrintPreview // WILL NOT be called and that cleanup, including deleting pState // must be done here. if (!DoPrintPreview(XTP_IDD_PREVIEW_DIALOGBAR, this, RUNTIME_CLASS(CXTPPreviewView), pState)) { // In derived classes, reverse special window handling here for // Preview failure case TRACE0("Error: DoPrintPreview failed.\n"); AfxMessageBox(AFX_IDP_COMMAND_FAILURE); delete pState; // preview failed to initialize, delete State now pState = NULL; return; } CFrameWnd* pFrameWnd = DYNAMIC_DOWNCAST(CFrameWnd, AfxGetMainWnd()); if (pFrameWnd) { CXTPPreviewView* pPPView = DYNAMIC_DOWNCAST(CXTPPreviewView, pFrameWnd->GetActiveView()); if (pPPView && pPPView->GetCommandBar()) { CXTPImageManager* pImgMgr = pPPView->GetCommandBar()->GetImageManager(); if (pImgMgr) { pImgMgr->RemoveIcon(XTP_ID_PREVIEW_PRINT); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_PREV); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_NEXT); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_ZOOMIN); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_ZOOMOUT); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_ONEPAGE); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_TWOPAGE); pImgMgr->RemoveIcon(XTP_ID_PREVIEW_CLOSE); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_PRINT, XTP_ID_PREVIEW_PRINT, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_SYMBOL_ARROW_LEFT, XTP_ID_PREVIEW_PREV, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_SYMBOL_ARROW_RIGHT, XTP_ID_PREVIEW_NEXT, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_ZOOM_IN, XTP_ID_PREVIEW_ZOOMIN, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_ZOOM_OUT, XTP_ID_PREVIEW_ZOOMOUT, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_VIEW_PAGE_LAYOUT, XTP_ID_PREVIEW_ONEPAGE, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_VIEW_PAGE_FOUR, XTP_ID_PREVIEW_TWOPAGE, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_NORMAL_CLOSE, XTP_ID_PREVIEW_CLOSE, XTP_DPI_X(16)); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_PRINT, XTP_ID_PREVIEW_PRINT, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_SYMBOL_ARROW_LEFT, XTP_ID_PREVIEW_PREV, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_SYMBOL_ARROW_RIGHT, XTP_ID_PREVIEW_NEXT, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_ZOOM_IN, XTP_ID_PREVIEW_ZOOMIN, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_ZOOM_OUT, XTP_ID_PREVIEW_ZOOMOUT, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_VIEW_PAGE_LAYOUT, XTP_ID_PREVIEW_ONEPAGE, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_VIEW_PAGE_FOUR, XTP_ID_PREVIEW_TWOPAGE, XTP_DPI_X(16), xtpImageDisabled); pImgMgr->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_CLOSE, XTP_ID_PREVIEW_CLOSE, XTP_DPI_X(16), xtpImageDisabled); pPPView->GetCommandBar()->Redraw(); } } } }