Files
Slnkdwf/Viewer/MainFrm.cpp
Jos Groot Lipman 185babff53 Versie 2.80
svn path=/Slnkdwf/trunk/; revision=12530
2012-01-11 19:23:50 +00:00

264 lines
7.2 KiB
C++

// MainFrm.cpp : implmentation of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "aboutdlg.h"
#include "FindDlg.h"
#include "SLNKDwfViewerView.h"
#include "MainFrm.h"
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
return TRUE;
return m_view.PreTranslateMessage(pMsg);
}
BOOL CMainFrame::OnIdle()
{
UIUpdateToolBar();
return FALSE;
}
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CreateSimpleToolBar();
CreateSimpleStatusBar();
m_status.Attach(m_hWndStatusBar);
ATLTRACE("\nEarly with m_Combo %x", m_Combo.m_hWnd);
m_wndSplit.Create ( *this, rcDefault );
m_hWndClient = m_wndSplit;
m_wndLayers.Create(m_wndSplit, rcDefault);
m_view.Create(m_wndSplit, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
m_wndSplit.SetSplitterPanes ( m_wndLayers, m_view );
m_wndLayers.AddColumn("Laag", 0);
m_wndLayers.SetColumnWidth(0, 195);
//m_wndLayers.AddColumn("#Cont", 1);
//m_wndLayers.AddItem(0, 0, "Hallo");
//m_wndLayers.AddItem(1, 1, "Jij");
UpdateLayout();
m_wndSplit.SetSplitterPos ( 200 );
UIAddToolBar(m_hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
// register object for message filtering and idle updates
// TODO: Het volgende crashed en lijkt niet echt nodig?
// CMessageLoop* pLoop = _Module.GetMessageLoop();
// ATLASSERT(pLoop != NULL);
/// pLoop->AddMessageFilter(this);
/// pLoop->AddIdleHandler(this);
// Create ComboBox in ToolBar
RECT rcCombo = { 190, 1, 440, 200 }; // Hardcode position for now...
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_SIMPLE | CBS_DROPDOWNLIST;
ATLTRACE("\nAbout to Create with m_Combo %x", m_Combo.m_hWnd);
m_Combo.Create(m_hWnd, rcCombo, NULL, dwStyle, 0, IDC_COMBO);
m_Combo.SetFont(AtlGetDefaultGuiFont());
m_Combo.SetParent(m_hWndToolBar);
return 0;
}
void CMainFrame::SetDWF(const CString &dwfPath)
{
SetWindowText(dwfPath);
m_view.SetDWF(dwfPath);
// Maak de pagina's aan
m_Combo.ResetContent();
// m_wndLayers.resetcontent
try
{
CDWFFileImpl m_iDWFFile;
CEPlotSectionsImpl *piEPlotSections;
m_iDWFFile.Open(dwfPath);
piEPlotSections = m_iDWFFile.get_EPlotSections();
LONG lCount;
lCount = piEPlotSections->get_Count();
for (LONG i=0; i<lCount; i++)
{
CEPlotSectionImpl *piEPlotSection;
piEPlotSection = piEPlotSections->get_Item(i);
m_Combo.AddString(piEPlotSection->get_Title());
}
ATLTRACE("\nDone filling ComboBox");
//CWhip2DCImpl *m_iWhip2DC = m_view.GetWhip2DC();
CWhip2DCImpl m_iWhip2DC;
if (lCount > 0)
{
m_iWhip2DC.Load(NULL, piEPlotSections->get_Item(0 /*m_nPage*/), L"", L".*",
1000, 800, VARIANT_TRUE /*center*/, VARIANT_FALSE /* Maximize */);
}
else
{
m_iWhip2DC.Load(NULL, NULL, dwfPath, L".*", 1000, 800, VARIANT_TRUE /*center*/, VARIANT_FALSE /* Maximize */);
}
m_iWhip2DC.FindTexts(""); // forceer een scan
m_iWhip2DC.get_LayerCount(&lCount);
for (int i=0;i < lCount;i++)
{
CString tLayer;
m_iWhip2DC.get_LayerItem(i, &tLayer);
m_wndLayers.AddItem(i, 0, tLayer);
}
ATLTRACE("\nDone filling layers");
}
catch (CString &ee)
{
ATLTRACE(ee);
//DoMessage(dc, ee); // komt later vanzelf wel
}
m_Combo.SetCurSel(0);
}
LRESULT CMainFrame::OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CFileDialog dlg(TRUE, _T("dwf"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("DWF Files (*.dwf)\0*.dwf\0All Files (*.*)\0*.*\0"), m_hWnd);
if(dlg.DoModal() == IDOK)
{
m_view.SetDWF(CString(dlg.m_szFileName));
}
return 0;
}
LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PostMessage(WM_CLOSE);
return 0;
}
LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndToolBar);
::ShowWindow(m_hWndToolBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_TOOLBAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::onSelChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
int nTab = m_Combo.GetCurSel();
m_view.SetPage(nTab);
return 0;
}
LRESULT CMainFrame::OnZoomExtents(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_view.Zoom(1.0);
return 0;
}
LRESULT CMainFrame::OnZoomIn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_view.Zoom(m_view.GetZoomScale() * (1 + m_view.GetZoomDelta()));
m_view.NotifyParentZoomChanged();
return 0;
}
LRESULT CMainFrame::OnZoomOut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_view.Zoom(m_view.GetZoomScale() / (1 + m_view.GetZoomDelta()));
m_view.NotifyParentZoomChanged();
return 0;
}
LRESULT CMainFrame::OnFilePrint(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CPrintDialog dlg(FALSE);
dlg.m_pd.hDevMode = m_devmode.CopyToHDEVMODE();
dlg.m_pd.hDevNames = m_printer.CopyToHDEVNAMES();
dlg.m_pd.nMinPage = 1;
dlg.m_pd.nMaxPage = m_Combo.GetCount();
if(dlg.DoModal() == IDOK)
{
m_devmode.CopyFromHDEVMODE(dlg.m_pd.hDevMode);
m_printer.ClosePrinter();
m_printer.OpenPrinter(dlg.m_pd.hDevNames, m_devmode.m_pDevMode);
CPrintJob job;
job.StartPrintJob(false, m_printer, m_devmode.m_pDevMode, this, m_view.m_dwfPath, 0, 0, (dlg.PrintToFile() != FALSE));
}
::GlobalFree(dlg.m_pd.hDevMode);
::GlobalFree(dlg.m_pd.hDevNames);
return 0;
}
LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
int nTab = m_Combo.GetCurSel();
CFindDlg dlg2(m_view.m_dwfPath, nTab);
dlg2.DoModal();
return 0;
}
LRESULT CMainFrame::OnViewLayers(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// CLayerDlg dlg(m_view.GetWhip2DC());
// dlg.DoModal();
return 0;
}
//print job info callbacks
bool CMainFrame::IsValidPage(UINT nPage)
{
return (nPage == 0); // we have only one page
}
bool CMainFrame::PrintPage(UINT nPage, HDC hDC)
{
if (nPage >= 1) // we have only one page
return false;
CRect rcPage
( 0, 0,
::GetDeviceCaps(hDC, PHYSICALWIDTH) - 2 * ::GetDeviceCaps(hDC, PHYSICALOFFSETX),
::GetDeviceCaps(hDC, PHYSICALHEIGHT) - 2 * ::GetDeviceCaps(hDC, PHYSICALOFFSETY) );
CDCHandle dc = hDC;
CClientDC dcScreen(m_hWnd);
CDC dcMem;
dcMem.CreateCompatibleDC(dcScreen);
CWhip2DCImpl iWhip2DC;
PaintToDC(hDC, m_view.m_dwfPath, 0, iWhip2DC, rcPage.Size(), TRUE);
return true;
}