// ShitarabianLogicImp.cpp: CShitarabianLogicImp クラスのインプリメンテーション
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "shitarabianLogic.h"
#include "ShitarabianLogicImp.h"
#include "Setting.h"
#include "DocumentIF.h"
#include "Common.h"
#include "ScanLogicPuzzle.h"

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



//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////

CShitarabianLogicImp::CShitarabianLogicImp()
{

}

CShitarabianLogicImp::~CShitarabianLogicImp()
{

}

const char* CShitarabianLogicImp::GetPlugInName()
{
	return( "ロジックパズル ver1.1" );
}

void CShitarabianLogicImp::OnSetting( CDocumentIF* pDocIF )
{
	CSetting dlg;
	dlg.pDocIF = pDocIF;

	static BOOL bTemp = FALSE;
	dlg.m_bEnable = bTemp;
	
	if ( dlg.DoModal() == IDOK )
	{
		bTemp = dlg.m_bEnable;
		if ( dlg.m_bEnable )
		{
			pDocIF->EntryToolBar( IDR_LOGIC );
			pDocIF->ShowToolBar( TRUE );
		}
		else
		{
			pDocIF->ShowToolBar( FALSE );
		}
	}
}

void CShitarabianLogicImp::OnToolButton( CDocumentIF* pDocIF , int idxButton )
{
	CString 
		strBlack,
		strWhite,
		strEndl;
	
	//■
	strBlack = "■";
	//□
	strWhite = "□";

	//改行
	strEndl += 0x0D;
	strEndl += 0x0A;
	
	switch ( idxButton )
	{
	case 0:
		{
			pDocIF->Insert( strWhite );
			break;
		}
	case 1:
		{
			pDocIF->Insert( strBlack );
			break;
		}
	case 2:
		{
			CString strLogic;
			
			if ( pDocIF->IsSelected() )
			{
				strLogic = pDocIF->GetSelectedText();
			}
			else
			{
				int iAllLine = 0;
				iAllLine = pDocIF->GetLineCount();
				
				//取り込み
				for ( int iCount = 0; iCount < iAllLine; iCount++ )
				{
					strLogic += pDocIF->GetLine( iCount );
					//最後の行には改行は無いので
					if ( iCount < iAllLine - 1 )
					{
						strLogic += 0x0A;
					}
				}
			}

			//スキャンしたのを生成
			ScanLogicPuzzle SLPlogic;
			
			if ( SLPlogic.Scan( ( uchar* )( ( LPCTSTR )strLogic ) ) == TRUE )
			{
				pDocIF->FileEnd();
				pDocIF->Insert( strEndl );
				pDocIF->Insert( SLPlogic.GetScaned() );
			}
			break;
		}
	case 3:
		{
						CString strLogic;

			
			if ( pDocIF->IsSelected() )
			{
				strLogic = pDocIF->GetSelectedText();
			}
			else
			{
				int iAllLine = 0;
				iAllLine = pDocIF->GetLineCount();
				
				//取り込み
				for ( int iCount = 0; iCount < iAllLine; iCount++ )
				{
					strLogic += pDocIF->GetLine( iCount );
					//最後の行には改行は無いので
					if ( iCount < iAllLine - 1 )
					{
						strLogic += 0x0A;
					}
				}
			}

			//スキャンしたのを生成
			ScanLogicPuzzle SLPlogic;
			
			if ( SLPlogic.Scan( ( uchar* )( ( LPCTSTR )strLogic ) ) == TRUE )
			{
				pDocIF->FileEnd();
				pDocIF->Insert( strEndl );
				pDocIF->Insert( SLPlogic.GetQuestion() );
			}
		}

	}
	pDocIF->ReDraw();
}

		
