// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Vector.h" #include "MainFrm.h" #include "VecDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(ID_PREFERENCES_APPLYTRANSFORMSBEFORESAVING, OnPreferencesApplytransformsbeforesaving) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_APPLYTRANSFORMSBEFORESAVING, OnUpdatePreferencesApplytransformsbeforesaving) ON_COMMAND(ID_HELP_INSTRUCTIONS, OnHelpInstructions) ON_UPDATE_COMMAND_UI(ID_CUSTOM_PANE, OnCustomPane) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_DRAGDROP, OnPreferencesShowDragdrop) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_DRAGDROP, OnUpdatePreferencesShowDragdrop) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_FOCUS, OnPreferencesShowFocus) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_FOCUS, OnUpdatePreferencesShowFocus) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_KEY, OnPreferencesShowKey) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_KEY, OnUpdatePreferencesShowKey) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_MOUSE, OnPreferencesShowMouse) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_MOUSE, OnUpdatePreferencesShowMouse) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_PAINT, OnPreferencesShowPaint) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_PAINT, OnUpdatePreferencesShowPaint) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SCROLL, OnPreferencesShowScroll) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SCROLL, OnUpdatePreferencesShowScroll) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SIZE, OnPreferencesShowSize) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SIZE, OnUpdatePreferencesShowSize) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_VECTOR, OnUpdatePreferencesShowVector) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_VECTOR, OnPreferencesShowVector) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_ZOOM, OnPreferencesShowZoom) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_ZOOM, OnUpdatePreferencesShowZoom) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_NONE, OnPreferencesShowNone) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_NONE, OnUpdatePreferencesShowNone) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_ALL, OnPreferencesShowAll) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_ALL, OnUpdatePreferencesShowAll) ON_COMMAND(ID_PREFERENCES_USELVECTORWINDOWAS_CONTROL, OnPreferencesUselvectorwindowasControl) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_USELVECTORWINDOWAS_CONTROL, OnUpdatePreferencesUselvectorwindowasControl) ON_COMMAND(ID_PREFERENCES_USELVECTORWINDOWAS_WINDOW, OnPreferencesUselvectorwindowasWindow) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_USELVECTORWINDOWAS_WINDOW, OnUpdatePreferencesUselvectorwindowasWindow) ON_COMMAND(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SCALE, OnPreferencesShowScale) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_SHOWNOTIFICATIONMESSAGESINSTATUSBAR_SCALE, OnUpdatePreferencesShowScale) ON_WM_PALETTECHANGED() ON_WM_QUERYNEWPALETTE() ON_WM_DESTROY() ON_COMMAND(ID_PREFERENCES_AUTOMATION, OnPreferencesAutomation) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_AUTOMATION, OnUpdatePreferencesAutomation) ON_WM_SYSCOLORCHANGE() ON_WM_PALETTEISCHANGING() ON_WM_DROPFILES() //}}AFX_MSG_MAP END_MESSAGE_MAP() extern CVectorApp theApp; static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_CUSTOM_PANE, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_bApplyTransformsBeforeSave = FALSE; m_uNotificationMessageFlag = FLAG_NONE_MSG; m_bCreateAsControl = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { //Start Automation and create toolbar if (theApp.m_bUseAutomation) { POINT pt; RECT rcClient; GetClientRect(&rcClient); ClientToScreen(&rcClient); pt.x = rcClient.left; pt.y = rcClient.top; theApp.StartAutomation(m_hWnd, &pt); } if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } UINT nItemID; UINT nItemStyle; L_INT cxItemWidth; m_wndStatusBar.GetPaneInfo(0, nItemID, nItemStyle, cxItemWidth); m_wndStatusBar.SetPaneInfo(0, nItemID, nItemStyle & (~SBPS_STRETCH), cxItemWidth = 200); m_wndStatusBar.SetPaneInfo(1, ID_CUSTOM_PANE, SBPS_POPOUT | SBPS_STRETCH, 0); // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CMDIFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnPreferencesApplytransformsbeforesaving() { m_bApplyTransformsBeforeSave = !m_bApplyTransformsBeforeSave; } void CMainFrame::OnUpdatePreferencesApplytransformsbeforesaving(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bApplyTransformsBeforeSave); pCmdUI->Enable(!theApp.m_bViewOnly); } L_INT CMainFrame::GetDocumentCount() { L_INT iCounter = 0; POSITION pos = theApp.GetFirstDocTemplatePosition(); while (pos) { CDocTemplate* pTemplate = (CDocTemplate*)theApp.GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { CDocument * pDocument; if ((pDocument=pTemplate->GetNextDoc(pos2)) != NULL) iCounter++; } } return iCounter; } void CMainFrame::OnHelpInstructions() { CDialog DialogInstructions(MAKEINTRESOURCE (IDD_DIALOG_INSTRUCTIONS), this); DialogInstructions.DoModal(); } void CMainFrame::OnCustomPane(CCmdUI *pCmdUI) { pCmdUI->Enable(); } void CMainFrame::UpdateStatusBar(L_UINT32 uFlagMsg, L_TCHAR *szMsg, pVECTORPOINT pPoint) { static iCount = 0; L_TCHAR szTemp[256],szLoc[256]; L_CHAR TmpszLoc[256]; if (pPoint != NULL) { sprintf(TmpszLoc, "%Lf, %Lf", pPoint->x, pPoint->y ); #ifdef _UNICODE MultiByteToWideChar(CP_ACP, 0,TmpszLoc,-1,szLoc,sizeof(szLoc)); #else strcpy(szLoc,TmpszLoc); #endif m_wndStatusBar.SetPaneText(0, szLoc, TRUE); } if (uFlagMsg & m_uNotificationMessageFlag) { iCount = (iCount+1)%1000; wsprintf(szTemp, TEXT("[%d]%s"), iCount, szMsg); m_wndStatusBar.SetPaneText(1, szTemp, TRUE); } } void CMainFrame::OnPreferencesShowDragdrop() { m_uNotificationMessageFlag ^= FLAG_DRAGDROP_MSG; if ((m_uNotificationMessageFlag & FLAG_DRAGDROP_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Drag Drop Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Drag Drop Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowDragdrop(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_DRAGDROP_MSG); } void CMainFrame::OnPreferencesShowFocus() { m_uNotificationMessageFlag ^= FLAG_FOCUS_MSG; if ((m_uNotificationMessageFlag & FLAG_FOCUS_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Focus Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Focus Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowFocus(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_FOCUS_MSG); } void CMainFrame::OnPreferencesShowKey() { m_uNotificationMessageFlag ^= FLAG_KEY_MSG; if ((m_uNotificationMessageFlag & FLAG_KEY_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Key Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Key Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowKey(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_KEY_MSG); } void CMainFrame::OnPreferencesShowMouse() { m_uNotificationMessageFlag ^= FLAG_MOUSE_MSG; if ((m_uNotificationMessageFlag & FLAG_MOUSE_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Mouse Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Mouse Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowMouse(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_MOUSE_MSG); } void CMainFrame::OnPreferencesShowPaint() { m_uNotificationMessageFlag ^= FLAG_PAINT_MSG; if ((m_uNotificationMessageFlag & FLAG_PAINT_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Paint Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Paint Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowPaint(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_PAINT_MSG); } void CMainFrame::OnPreferencesShowScroll() { m_uNotificationMessageFlag ^= FLAG_SCROLL_MSG; if ((m_uNotificationMessageFlag & FLAG_SCROLL_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Scroll Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Scroll Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowScroll(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_SCROLL_MSG); } void CMainFrame::OnPreferencesShowSize() { m_uNotificationMessageFlag ^= FLAG_SIZE_MSG; if ((m_uNotificationMessageFlag & FLAG_SIZE_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Size Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Size Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowSize(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_SIZE_MSG); } void CMainFrame::OnUpdatePreferencesShowVector(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_VECTORCHANGED_MSG); } void CMainFrame::OnPreferencesShowVector() { m_uNotificationMessageFlag ^= FLAG_VECTORCHANGED_MSG; if ((m_uNotificationMessageFlag & FLAG_VECTORCHANGED_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Vector Changed Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Vector Changed Enabled"), TRUE); } void CMainFrame::OnPreferencesShowZoom() { m_uNotificationMessageFlag ^= FLAG_ZOOM_MSG; if ((m_uNotificationMessageFlag & FLAG_ZOOM_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Zoom Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Zoom Changed Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowZoom(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_ZOOM_MSG); } void CMainFrame::OnPreferencesShowNone() { m_uNotificationMessageFlag = FLAG_NONE_MSG; m_wndStatusBar.SetPaneText(1,TEXT("All Messages Disabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowNone(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag == FLAG_NONE_MSG); } void CMainFrame::OnPreferencesShowAll() { m_uNotificationMessageFlag = FLAG_ALL_MSG; m_wndStatusBar.SetPaneText(1,TEXT("All Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowAll(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag == FLAG_ALL_MSG); } void CMainFrame::OnPreferencesUselvectorwindowasControl() { m_bCreateAsControl = TRUE; } void CMainFrame::OnUpdatePreferencesUselvectorwindowasControl(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bCreateAsControl); } void CMainFrame::OnPreferencesUselvectorwindowasWindow() { m_bCreateAsControl = FALSE; } void CMainFrame::OnUpdatePreferencesUselvectorwindowasWindow(CCmdUI* pCmdUI) { pCmdUI->SetCheck(!m_bCreateAsControl); } void CMainFrame::OnPreferencesShowScale() { m_uNotificationMessageFlag ^= FLAG_SCALE_MSG; if ((m_uNotificationMessageFlag & FLAG_SCALE_MSG) == 0) m_wndStatusBar.SetPaneText(1,TEXT("Scale Messages Disabled"), TRUE); else m_wndStatusBar.SetPaneText(1,TEXT("Scale Messages Enabled"), TRUE); } void CMainFrame::OnUpdatePreferencesShowScale(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_uNotificationMessageFlag & FLAG_SCALE_MSG); } BOOL CMainFrame::OnQueryNewPalette() { CMDIChildWnd* pMDIChildWnd = MDIGetActive(); if (pMDIChildWnd) { CView* pView = pMDIChildWnd->GetActiveView(); if(pView) { pView->SendMessage(WM_HANDLEPALETTE,0,FALSE); return TRUE; } } return FALSE; } void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) { if(pFocusWnd!=NULL) SendMessageToDescendants(WM_HANDLEPALETTE,(WPARAM)pFocusWnd->m_hWnd,TRUE); } void CMainFrame::OnSysColorChange() { OnQueryNewPalette(); } void CMainFrame::OnPaletteIsChanging(CWnd* pRealizeWnd) { OnPaletteChanged (pRealizeWnd); } void CMainFrame::OnDestroy() { if (theApp.m_bUseAutomation) { theApp.StopAutomation(); } CMDIFrameWnd::OnDestroy(); } void CMainFrame::OnPreferencesAutomation() { L_BOOL bContinue = TRUE; L_INT iCount = GetDocumentCount(); if (iCount>0) { L_TCHAR szTemp[100]; wsprintf(szTemp, TEXT("This operation will close %d child windows. Continue?"), iCount); bContinue = (AfxMessageBox(szTemp,MB_OKCANCEL) != IDCANCEL); if (bContinue) theApp.CloseAllDocuments(TRUE); } if (bContinue) { if (theApp.m_bUseAutomation) { theApp.StopAutomation(); } else { POINT pt; RECT rcClient; GetClientRect(&rcClient); ClientToScreen(&rcClient); pt.x = rcClient.left; pt.y = rcClient.top; theApp.StartAutomation(m_hWnd, &pt); } theApp.m_bUseAutomation = !theApp.m_bUseAutomation; } } void CMainFrame::OnUpdatePreferencesAutomation(CCmdUI* pCmdUI) { pCmdUI->SetCheck(theApp.m_bUseAutomation); pCmdUI->Enable(!theApp.m_bViewOnly); } void CMainFrame::OnDropFiles(HDROP hDropInfo) { // TODO: Add your message handler code here and/or call default L_TCHAR szFilePath[255]; int nCount; int i; nCount = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0); for(i=0; i< nCount; i++) { DragQueryFile(hDropInfo, i, szFilePath, 255); // CWinApp::OpenDocumentFile(szFilePath); } CMDIFrameWnd::OnDropFiles(hDropInfo); }