// BookShelfView.h : interface of the CBookShelfView class
//
/////////////////////////////////////////////////////////////////////////////

#include ".\\include\\ximage.h"
//#pragma comment(lib, ".\\lib\\readerc")

#if !defined(AFX_BOOKSHELFVIEW_H__721658CC_35F4_41BB_AAB3_9C24B5D6D1A8__INCLUDED_)
#define AFX_BOOKSHELFVIEW_H__721658CC_35F4_41BB_AAB3_9C24B5D6D1A8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <list> 
#include "MyReader-DUI-MFCDoc.h"
#include "include\\memdc.h"
#include "ReaderFrame.h"
#include "BookDal.h"
#include "LogFile.h"
#include "DownFrame.h"
#include "SelectTargetFrame.h"
//����ͼ�Ĵ�С
//#define	THUMBNAIL_WIDTH		107
//#define	THUMBNAIL_HEIGHT	130
//#define	COVER_WIDTH		90
//#define	COVER_HEIGHT	128
//#define	COVER_HEIGHT	127
//#define	SHELF_HEIGHT	150
//#define	 BOOK_SPAN	50
//#define	 ROW_SPAN	    50

class CMyLibDoc;



typedef struct tagWNDINFO
{
	DWORD dwProcessId;
	HWND hWnd;    
} WNDINFO, *LPWNDINFO;


class CBookShelfView : public CScrollView
{
public: // create from serialization only
	CBookShelfView();
	void ReLoadShelf();
	DECLARE_DYNCREATE(CBookShelfView)

	// Attributes
public:
	bool IsRunning();
	CMyReaderDUIMFCDoc* GetDocument();

	

	int m_index;//��ʾ��ǰ�鼮������ʷ�鼮 1��ǰ 2��ʷ

	bool m_bIsManage;//�Ƿ�Ϊ����ģʽ

	void DrawABook( CBookInfo info,RECT rc,CDC* dc );
	void DrawBook(CDC* dc);
	void CalculatePosition(int count,int index,RECT& trc,int nButtom=0);
	void DrawAllBookByYear(CString strYear,std::vector<CBookInfo> YearBookList,CDC* dc);
	std::vector<CRect> m_rect_list;

	//CBookInfo* GetBookInfoByIndex(int index);

	void DrawDownProcess(CDC* dc,CBookInfo info,RECT rc);
	void DrawMoveTag(CDC* dc,RECT rc,CString year);
	CxImage m_bookMark;
	CBookInfo* GetBookInfoByIndex(int index);

	void GetSelectBookIndex(std::vector<int>& list);
	// Operations
public:

	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBookShelfView)
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 
protected:
	//}}AFX_VIRTUAL

	// Implementation
public:
	virtual ~CBookShelfView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	// Generated message map functions
protected:
	//{{AFX_MSG(CBookShelfView)
	// NOTE - the ClassWizard will add and remove member functions here.
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
public:
	int MiniaturePaint();
	void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
	int m_nScorllCount;
	CxImage m_imgShelf;
	CxImage m_imgShelfTitleBar;
	CxImage m_imgFrame;
	CBookDal m_BookDal;
	int     m_iCatalogId;
	CLogFile m_Log;
	
	CxImage m_imgFrameBig;

	CxImage m_imgDownloadBlank;
	CxImage m_imgDownloadPause;
	CxImage m_imgDownloadWait;
	CxImage m_imgDownloadWait_Icon;
	CxImage m_imgDownloadHold;
	CxImage m_imgDownloadAgain;
	CxImage m_imgDownloadContinue;
	CxImage m_imgDownloadDoing;
	CxImage* m_pImgDownloadBook;
	CxImage m_pImgDownloadBook_start;
	int m_MouseDownIndex;
	//�鼮�ƶ�Ԥ��
	CStatic m_BookMovePic;
	int m_nPic_Height;
	int m_nPic_Width;
	CxImage* m_cximg;
	CImage m_img;
	CxImage m_cXimg;
	HBITMAP m_hbitmap;
	void  CBookShelfView::ReOrderBooks(int nDownIndex,int nUpIndex);
	CString m_str_CoverPath;
	CFont m_font;
	CPoint m_MousePoint;
	int m_nMouseIndex;
	int m_nMouseIndexEnd;
	BOOL m_bMouseDown;
	////////////////
	HFONT   m_hFontTag;
	//CStringArray 
	CMemDCEx* m_pMemDC;
	int m_curHighlightBook;
	int m_row;
	int m_col;
	
	int	m_ThumbnailWidth;//		107
	int m_ThumbnailHeight;//	130
	int m_CoverWidth;
	int m_CoverHeight;
	int m_CoverLeft;
	int m_CoverTop;
	int m_FrameTop;
	int m_BookSpan;
	int m_ShelfHeight;
	int m_RowSpan;
	CRect m_rcRectShelf;
	int m_nSelectBook;
	CRect m_RcSelect;
	CPoint m_OldPos;
	CPoint m_CurrentPos;
	BOOL m_bDrawing;
	BOOL m_bIsCreateReadFrame;
	int index_pos;
	//float m_position;
	//#define	COVER_WIDTH		98
	//#define	COVER_HEIGHT	130
	//#define	COVER_HEIGHT	127
	//#define	SHELF_HEIGHT	170
	void ResetVscrollSize();
	virtual void OnInitialUpdate();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	int GetImageIndexByPos(CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	void GetDecFile(CString inFileName,CString outFileName);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	HWND GetWindowHandleByPID(DWORD dwProcessID);
	HWND GetProcessMainWnd(DWORD dwProcessId);
	void OpenBook(CBookInfo *bookInfo);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	BOOL OpenBookByBookIdAndPageIndex();
	void DrawBookName(CDC* pDC,CString text,int left,int top,int width,CFont &cFont,int nAlient=DT_LEFT);
	void DrawManageFlag(CDC* pDC,CRect rc,bool select);
	void SetBookState(int nIndex,int nType);
	void DeleteBook(int nIndex);
	void DeleteBook(CBookInfo* bookInfo);
	void MoveBookOperation(int nIndex,int nMoveToCurrent=1);//1=Move to Current
	void MoveBookOperation(CBookInfo* bookInfo,int nMoveToCurrent=1);//1=Move to Current
	int CBookShelfView::ChangeSelectIndexBySearch(int nIndex);
	int CBookShelfView::CheckIsSearchResult(ListBookInfo& list,int nIndex,CString text);
	//Add By Ray 2018-06-11
	void DrawSelRect(CDC* pDC);
	//Add By Ray 2018-11-21
	BOOL StartDownloadBook(int nHoistory,CString bookId);
	void ContinueDownloadBook(int nHoistory,CString strBookId);
	//Add By Ray 2019-04-17
	void MoveToBookDesk();
	void RemoveFromBookDesk();
	void DeleteBooks();
	DuiLib::CReaderFrame* m_pReaderFrame;
	
	
	//void OpenBook(CBookInfo *bookInfo);
	//static DWORD WINAPI ThreadBookOrder(LPVOID param);
	CMyReaderDUIMFCDoc* m_pDoc;
	std::vector<Book_Manager> m_BookManager;
	CDownFrame* m_pMsgBox;
	BOOL m_bEndLoading;
	void  SetBookOrder();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	private:
	//�����
	BOOL m_bMenuClick;
	CString m_strBookId;
};

#ifndef _DEBUG  // debug version in BookShelfView.cpp
inline CMyReaderDUIMFCDoc* CBookShelfView::GetDocument()
{ return (CMyReaderDUIMFCDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BOOKSHELFVIEW_H__721658CC_35F4_41BB_AAB3_9C24B5D6D1A8__INCLUDED_)