// CommandBarsDesignerPreviewView.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 "CommandBarsDesigner.h" #include "CommandBarsDesignerDoc.h" #include "IPCData.h" #include "IPCChannel.h" #include "EmbeddedFrame.h" #include "CommandBarsDesignerPreviewView.h" #include "MainFrm.h" #include "DialogResourceSymbols.h" #include "DialogMenuGrabber.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCommandBarsDesignerPreviewView IMPLEMENT_DYNCREATE(CCommandBarsDesignerPreviewView, CView) BEGIN_MESSAGE_MAP(CCommandBarsDesignerPreviewView, CView) //{{AFX_MSG_MAP(CCommandBarsDesignerPreviewView) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCommandBarsDesignerPreviewView construction/destruction CCommandBarsDesignerPreviewView::CCommandBarsDesignerPreviewView() : m_bWaitingForPreviewHost(FALSE) { m_pChannel = new CIPCChannel(*this); } CCommandBarsDesignerPreviewView::~CCommandBarsDesignerPreviewView() { delete m_pChannel; } BOOL CCommandBarsDesignerPreviewView::PreCreateWindow(CREATESTRUCT& cs) { cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; return CView::PreCreateWindow(cs); } void CCommandBarsDesignerPreviewView::OnDraw(CDC* pDC) { UNREFERENCED_PARAMETER(pDC); } void CCommandBarsDesignerPreviewView::OnInitialUpdate() { CView::OnInitialUpdate(); if (!m_pChannel->IsOpen()) { InitPreviewHost(); } } BOOL CCommandBarsDesignerPreviewView::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult) { BOOL bResult = m_pChannel->ProcessMessage(message, wParam, lParam, *pResult); if (!bResult) { bResult = CView::OnWndMsg(message, wParam, lParam, pResult); if (WM_WINDOWPOSCHANGED == message || WM_WINDOWPOSCHANGING == message) { m_pChannel->PostNotification(ipcNtfReposition); } } return bResult; } void CCommandBarsDesignerPreviewView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CView::OnActivateView(bActivate, pActivateView, pDeactiveView); GetDocument()->GetFrame()->UpdatePreview(); ((CMainFrame*)AfxGetMainWnd())->RefreshPanes(); } void CCommandBarsDesignerPreviewView::OnIPCPeerConnected() { m_bWaitingForPreviewHost = FALSE; } LRESULT CCommandBarsDesignerPreviewView::OnIPCNotificationReceived(WORD /*wCode*/, LPARAM /*lParam*/) { return 0; } LRESULT CCommandBarsDesignerPreviewView::OnIPCDataReceived(WORD /*wCode*/, const void* /*pData*/, SIZE_T /*cbSize*/) { return 0; } void CCommandBarsDesignerPreviewView::OnIPCPeerDisconnected() { } void CCommandBarsDesignerPreviewView::OnSetPreviewSettings(const PREVIEW_SETTINGS* pSettings) { _ASSERTE(NULL != pSettings); if (m_pChannel->IsOpen()) { m_pChannel->SendData(ipcNtfPreviewSettings, pSettings, sizeof(*pSettings)); } } void CCommandBarsDesignerPreviewView::OnCommandBarsUpdated(LPCTSTR xmlData) { _ASSERTE(NULL != xmlData); if (m_pChannel->IsOpen()) { m_pChannel->SendData(ipcNtfCommandBarsData, xmlData, (_tcslen(xmlData) + 1) * sizeof(TCHAR)); } } void CCommandBarsDesignerPreviewView::OnTitleUpdated(LPCTSTR lpTitle) { _ASSERTE(NULL != lpTitle); if (m_pChannel->IsOpen()) { m_pChannel->SendData(ipcNtfSetTitle, lpTitle, (_tcslen(lpTitle) + 1) * sizeof(TCHAR)); } } void CCommandBarsDesignerPreviewView::OnWorkspaceColorUpdated(COLORREF crBackground) { if (m_pChannel->IsOpen()) { m_pChannel->SendNotification(ipcNtfSetWorkspaceColor, crBackground); } } void CCommandBarsDesignerPreviewView::OnHideMenu() { if (m_pChannel->IsOpen()) { m_pChannel->SendNotification(ipcNtfHideMenu); } } ///////////////////////////////////////////////////////////////////////////// // CCommandBarsDesignerPreviewView diagnostics #ifdef _DEBUG void CCommandBarsDesignerPreviewView::AssertValid() const { CView::AssertValid(); } void CCommandBarsDesignerPreviewView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CCommandBarsDesignerDoc* CCommandBarsDesignerPreviewView::GetDocument() // non-debug version is // inline { _ASSERTE(m_pDocument->IsKindOf(RUNTIME_CLASS(CCommandBarsDesignerDoc))); return (CCommandBarsDesignerDoc*)m_pDocument; } #endif //_DEBUG void CCommandBarsDesignerPreviewView::InitPreviewHost() { if (!m_pChannel->IsOpen() && !m_bWaitingForPreviewHost) { m_pChannel->OpenServerChannel(*this); TCHAR szPath[MAX_PATH + 1]; ::GetModuleFileName(NULL, szPath, _countof(szPath)); TCHAR szCmdLine[0x8000]; wsprintf(szCmdLine, _T("%s /Preview:%i"), szPath, static_cast(reinterpret_cast(m_hWnd))); PROCESS_INFORMATION pi = { 0 }; STARTUPINFO si = { 0 }; si.cb = sizeof(si); if (::CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { m_bWaitingForPreviewHost = TRUE; ::ResumeThread(pi.hThread); ::CloseHandle(pi.hProcess); ::CloseHandle(pi.hThread); DWORD dwStartTime = GetTickCount(); while (m_bWaitingForPreviewHost && ((GetTickCount() - dwStartTime) / 1000) < 10) // wait for 10 seconds at most { MSG msg; if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetThread()->PumpMessage()) break; } } if (m_bWaitingForPreviewHost) { m_pChannel->CloseChannel(); m_bWaitingForPreviewHost = FALSE; } } else { m_pChannel->CloseChannel(); } if (!m_pChannel->IsOpen()) { AfxMessageBox(_T("Unable to create preview host"), MB_ICONEXCLAMATION); } } } ///////////////////////////////////////////////////////////////////////////// // CCommandBarsDesignerPreviewView message handlers int CCommandBarsDesignerPreviewView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; return 0; }