#include "stdafx.h"
#include "facade_ui.h"

#include "UIClasses/win32mine.h"
#include "UIClasses/win32mineDoc.h"
#include "UIClasses/win32mineView.h"

void a_showFrawn()
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetFrawn();
    }
}

void a_showSmile()
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetSmile();
    }
}

void a_showCell(int irow, int icol)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(-5, irow, icol);
    }
}

void a_showFlag(int irow, int icol)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(-3, irow, icol);
    }
}

void a_showBlastedMine(int irow, int icol)
{
//    TRACE("a_showBlastedMine(%d,%d)\n", irow, icol);
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(-2, irow, icol);
    }
}

void a_showMine(int irow, int icol)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(-1, irow, icol);
    }
}

void a_showQuestionMark(int irow, int icol)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(-4, irow, icol);
    }
}

void a_showSurroundingMineCount(int count, int irow, int icol)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetCell(count, irow, icol);
    }
}

void a_setRemainingMineCount(int count)
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetMineCount(count);
    }
}

void a_startClock()
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineView *pView = (Cwin32mineView *)(pWnd->GetActiveView());
        pView->startTimer();
    }
}

void a_stopClock()
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function might be called before main window being opened for its first time
    {
        Cwin32mineView *pView = (Cwin32mineView *)(pWnd->GetActiveView());
        pView->stopTimer();
    }
}

void a_resetClock()
{
    CFrameWnd *pWnd = (CFrameWnd*)AfxGetMainWnd();
    if (pWnd) // this function is called before main window being opened for its first time
    {
        Cwin32mineDoc *pDoc = (Cwin32mineDoc *)(pWnd->GetActiveDocument());
        pDoc->SetClock(0);
    }
    a_stopClock();
}