Скачиваний:
12
Добавлен:
01.05.2014
Размер:
7.63 Кб
Скачать
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "Compiler.h"

#include "MainFrm.h"

#include "CompilerDoc.h"
#include "CompilerView.h"
#include "InfoVeiw.h"

#include "Interfaces.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
    ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOp)
    ON_UPDATE_COMMAND_UI (ID_INDICATOR_LINE, OnUpdateLineNumber)
    ON_WM_SIZE()
    ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileOp)
    ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileOp)
    ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileOp)
    ON_MESSAGE(WM_USER_APP_SET_BUSY, OnSetBusy)
	
    
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
    ID_INDICATOR_LINE,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL
};

//-----------------------------------------------------------------------------

IOutput *g_pOutput = NULL;

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
    m_bBusy = false;
    m_pView = NULL;
    m_bSplitterCreated = false;
}

CMainFrame::~CMainFrame()
{
}
//-----------------------------------------------------------------------------
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) /*||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)*/)
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

  	if (!m_CompilerToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(0,0,0,0), IDR_COMPILER_TOOLBAR) ||
		!m_CompilerToolBar.LoadToolBar(IDR_COMPILER_TOOLBAR))
	{
		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
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    m_CompilerToolBar.EnableDocking(CBRS_ALIGN_ANY);

	EnableDocking(CBRS_ALIGN_ANY);

	DockControlBar(&m_wndToolBar);
    DockControlBar(&m_CompilerToolBar);

    // Restore toolbars positions
    LoadBarState("ToolBars");

    // Load last window size and position
    WINDOWPLACEMENT *pWndPos;
    UINT size = 0;
    if ( AfxGetApp()->GetProfileBinary("MainWindow", "Position", (LPBYTE *)&pWndPos, &size) && (size == sizeof(WINDOWPLACEMENT)) )   
        SetWindowPlacement(pWndPos);
    delete pWndPos;

    // Load splitter position
    int cyCur, cyMin;
    m_Splitter.GetRowInfo(0, cyCur, cyMin);
    cyCur = AfxGetApp()->GetProfileInt("MainWindow", "SplitterPos", cyCur);
    m_Splitter.SetRowInfo(0, cyCur, cyMin);
    m_Splitter.RecalcLayout();

    int index = m_wndStatusBar.CommandToIndex(ID_INDICATOR_LINE);
    
    m_wndStatusBar.SetPaneText(index, "Ln 1");

	return 0;
}
//-----------------------------------------------------------------------------
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}
//-----------------------------------------------------------------------------
void CMainFrame::OnClose() 
{
    // Save toolbars positions to registry
    SaveBarState("ToolBars");
	
    // Save main window position in registry
    WINDOWPLACEMENT WndPos;
    if ( GetWindowPlacement(&WndPos) )
        AfxGetApp()->WriteProfileBinary("MainWindow", "Position", (LPBYTE) &WndPos, sizeof(WINDOWPLACEMENT));

    // Save splitter position
    int cyCur, cyMin;
    m_Splitter.GetRowInfo(0, cyCur, cyMin);
    AfxGetApp()->WriteProfileInt("MainWindow", "SplitterPos", cyCur);

	CFrameWnd::OnClose();
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	m_Splitter.CreateStatic(this, 2, 1);
    m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CCompilerView), CSize(0,0), pContext);
    m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CInfoVeiw), CSize(0,0), pContext);

    CRect ClientRect;
    GetClientRect(&ClientRect);

    m_Splitter.SetRowInfo(0, 50, 0);
    m_Splitter.SetRowInfo(1, 50, 0);

    m_pView   = (CEditView*)  m_Splitter.GetPane(0, 0);
    g_pOutput = (CInfoVeiw *) m_Splitter.GetPane(1, 0);
    
    ((CInfoVeiw *) g_pOutput)->GetEditCtrl().SetReadOnly();

    m_bSplitterCreated = true;

	return TRUE; //CFrameWnd::OnCreateClient(lpcs, pContext);
}
//-----------------------------------------------------------------------------

CCompilerView * CMainFrame::GetInfoPane()
{
    return ((CCompilerView *) m_Splitter.GetPane(1,0));
}

//-----------------------------------------------------------------------------

void CMainFrame::OnUpdateFileOp(CCmdUI* pCmdUI)
{
    pCmdUI->Enable(!m_bBusy);
}

//-----------------------------------------------------------------------------

LRESULT CMainFrame::OnSetBusy(WPARAM wparam, LPARAM)
{
    m_bBusy = (wparam != 0);
    return 0;
}
//-----------------------------------------------------------------------------
void CMainFrame::OnUpdateLineNumber(CCmdUI *pCmdUI)
{
    CString strCurPos;
    int nLineNum, nColNum;
    int nSelStart, nSelEnd;

    CEdit &EditCtrl = m_pView->GetEditCtrl();
    EditCtrl.GetSel(nSelStart, nSelEnd);
                                              
    nLineNum = EditCtrl.LineFromChar(nSelStart);

    nColNum = nSelStart - EditCtrl.LineIndex(nLineNum);

    strCurPos.Format(ID_INDICATOR_LINE, nLineNum+1, nColNum+1); 

    m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_LINE), strCurPos);
}
//-----------------------------------------------------------------------------
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
    CFrameWnd::OnSize(nType, cx, cy);
    
    if ((SIZE_MINIMIZED == nType) || (SIZE_MAXIMIZED == nType)) return;

    if (!m_bSplitterCreated)
        return;

    static int LastWindowHeight = cy;       // first time (LastWindowHeight == cy)

    int Cur, Min, delta = cy - LastWindowHeight;
    m_Splitter.GetRowInfo(0, Cur, Min);
    Cur = max(0, Cur + delta);
    m_Splitter.SetRowInfo(0, Cur, 10);
    m_Splitter.RecalcLayout();
    
    LastWindowHeight = cy;
}
//-----------------------------------------------------------------------------

Соседние файлы в папке Курсовая работа2