#include "stdafx.h"
#include "MyBook.h"
#include "MyReader-Win32\MyReader-win32\src\mainwnd.h"

extern V3DocViewWin * g_reader_win;
extern int InitMyReader(HINSTANCE hInstance, HWND hParent);
extern HWND g_hReader_win;

extern TP_NOTES_TYPE g_penNote_state;
extern DrawLineNotify* g_drawNotify;
extern int g_penNote_width;
extern lUInt32 g_penNote_color;
namespace DuiLib{

MyBook::MyBook(void)
{
}


MyBook::~MyBook(void)
{
}
void MyBook::SetPos( RECT rc )
{
	__super::SetPos(rc);

	g_reader_win->getWindowManager()->update(true);
}


bool MyBook::Create( HINSTANCE hInstance, HWND hParent, RECT rc )
{
	InitMyReader(hInstance, hParent);
	Attach(g_hReader_win);

	__super::Create(hInstance, hParent, rc);
	return true;
}

bool MyBook::Open( lString16 filename )
{
	bool ret = g_reader_win->loadDocument(filename);
	g_reader_win->getWindowManager()->update(true);
	return ret;
}

void MyBook::Close()
{
	g_reader_win->getDocView()->close();
	g_reader_win->getWindowManager()->update(true);
}

void MyBook::Show( int show_opt )
{
	ShowWindow(m_hWnd, show_opt);
}

LVTocItem * MyBook::GetTOC()
{
	return g_reader_win->getDocView()->getToc();
}

int MyBook::DoCommand( LVDocCmd cmd, int param/*=0 */ )
{
	return g_reader_win->getDocView()->doCommand(cmd, param);
}

bool MyBook::FindText( lString16 pattern, int origin, bool reverse, bool caseInsensitive )
{
	return g_reader_win->findText(pattern, origin, reverse, caseInsensitive);
}

void MyBook::GoToBookmark( ldomXPointer bm )
{
	g_reader_win->getDocView()->goToBookmark(bm);
}


//ҳ�����
//ȡ����ҳ��
int MyBook::GetPageCount(){
	return g_reader_win->getDocView()->getPageCount ();
}

//ȡ�õ�ǰҳ�롣
int MyBook::GetPageNum(){
	return g_reader_win->getDocView()->getCurPage();
}
//ת���ڼ�ҳ
void MyBook::GotoPageNum(int pageNum){
	/*TODO:FINISH*/
	g_reader_win->getDocView()->goToPage(pageNum);
}

TP_READER_TYPE MyBook::GetReaderType(){
	return EPUB_READER;
}

void MyBook::Destroy()
{
	g_reader_win->getWindowManager()->closeAllWindows();
	DestroyWindow(g_hReader_win);
}

long MyBook::SetupCallBack( long callback1, long callback2,long callbavk3, ... )
{
	return 0;
}

bool MyBook::GetPosByPoint( POINT pt, TP_POSITION_INFO &pos_info )
{
	throw std::exception("The method or operation is not implemented.");
}

bool MyBook::GetPointByPos( TP_POSITION_INFO &pos_info, POINT &pt )
{
	throw std::exception("The method or operation is not implemented.");
}

bool MyBook::GetNotesByPoint( POINT pt, TP_NOTES_INFO &notes_info )
{
	throw std::exception("The method or operation is not implemented.");
}

bool MyBook::DeleteComment( long id, long deleteAllKind )
{
	throw std::exception("The method or operation is not implemented.");
}

int MyBook::SetViewMode( int viewMode )
{
	throw std::exception("The method or operation is not implemented.");
}

void MyBook::GotoPosition( float position )
{
	throw std::exception("The method or operation is not implemented.");
}

BOOL MyBook::SetPDFNoteInfoList( vector<CPDFNoteInfo*>& pdfNoteInfos )
{
	throw std::exception("The method or operation is not implemented.");
}

BOOL MyBook::ShowAllComment( BOOL flag )
{
	throw std::exception("The method or operation is not implemented.");
}

void MyBook::ShowComment( long IndexID, long bShow )
{
	throw std::exception("The method or operation is not implemented.");
}

BOOL MyBook::RedrawLines()
{
	throw std::exception("The method or operation is not implemented.");
}

BOOL MyBook::SetLineMode( TP_NOTES_TYPE noteType, DWORD lineColor, int lineWidth, DrawLineNotify* drawNotify )
{
	throw std::exception("The method or operation is not implemented.");
}

void MyBook::FitWidth()
{
	throw std::exception("The method or operation is not implemented.");
}

}