#pragma once
#include "afxwin.h"
#include "CDVvWeb.h"
#include "kpi_player.h"
#include "kpi_impl.h"
//---------------------------------------------------------------------------
class KbVivPlayer : public CWnd, public KbKpiUnknownImpl<IKpiPlayer>
{
public:
    KPI_MEDIAINFO m_MediaInfo;
    CDVvWeb       m_VvWeb;
    IKpiFile     *m_pFile;
    BOOL          m_bVisible;
    BOOL          m_bPause;
    BOOL          m_bVvWebIsInstalled;
    wchar_t       m_szClassName[128];
    HANDLE        m_hEventCmd; //コマンド発行待ち用イベント
    HANDLE        m_hEventDone;//コマンド処理待ち用イベント
    CWinThread   *m_pThread;//m_VvWeb へのアクセスは全てこのスレッド内で行う
    enum {
        VIV_OPEN = 0,
        VIV_PLAY,
        VIV_PAUSE,
        VIV_RESTART,
        VIV_STOP,
        VIV_GETPOSITION,
        VIV_GETSTATUS,
        VIV_SETTEMPO,
        VIV_SETVOLUME,
        VIV_SETVISIBLE,
        VIV_GETWINDOWPOSITION,
        VIV_SETWINDOWPOSITION,
        VIV_SETTOPMOST,
        VIV_SETREPEAT,
        VIV_QUIT,
    };
    struct {
        int    nCommand;
        WPARAM wParam;
        LPARAM lParam;
        LPARAM lResult;
    }m_Command;

    DECLARE_MESSAGE_MAP()
    afx_msg void OnPaint();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnSizing(UINT fwSide, LPRECT pRect);

    LRESULT SendCommand(int nCommand, WPARAM wParam, LPARAM lParam);
    static UINT __cdecl ThreadProc(LPVOID pParam) {
        return ((KbVivPlayer*)pParam)->_ThreadProc();
    }
    //スレッド内で呼ぶ
    UINT  _ThreadProc(void);
    void  _CreateWindow(void);
    void  _DestroyWindow(void);
    BOOL  _Open(IKpiFile* pFile, IKpiFolder* pFolder);
    BOOL  _Play(DWORD dwStartPos, BOOL bVisible);
    BOOL  _Pause(void);
    BOOL  _Restart(void);
    void  _Stop(void);
    DWORD _GetPosition(void);
    DWORD _GetStatus(void);
    void  _SetTempo(int Tempo);
    void  _SetVolume(int Volume);
    void  _SetVisible(BOOL bVisible);
    void  _GetWindowPosition(int* pLeft, int* pTop,
                             int* pVideoWidth, int* pVideoHeight);
    void  _SetWindowPosition(int nLeft, int nTop,
                             int nVideoWidth, int nVideoHeight);
    void  _SetTopMost(BOOL bTopMost);
    void  _SetRepeat(BOOL bRepeat);
    //ここまで
public:		// ユーザー宣言
    KbVivPlayer(void);
    ~KbVivPlayer(void);
    BOOL __fastcall Open(IKpiFile *pFile, IKpiFolder *pFolder);
    DWORD WINAPI Select(DWORD dwNumber,
                        const KPI_MEDIAINFO **ppInfo,
                        IKpiTagInfo *pTagInfo,
                        DWORD dwTagGetFlags);
    BOOL  WINAPI Play(DWORD dwStartPos, BOOL bVisible);
    BOOL  WINAPI Pause(void);
    BOOL  WINAPI Restart(void);
    void  WINAPI Stop(void);
    DWORD WINAPI GetPosition(void);
    DWORD WINAPI GetStatus(void);
    void  WINAPI SetTempo(int Tempo);
    void  WINAPI SetVolume(int Volume);
    void  WINAPI SetVisible(BOOL bVisible);
    void  WINAPI GetWindowPosition(int *pLeft,  int *pTop,
                                   int *pVideoWidth, int *pVideoHeight);
    void  WINAPI SetWindowPosition(int nLeft, int nTop,
                                   int nVideoWidth, int nVideoHeight);
    void  WINAPI SetTopMost(BOOL bTopMost);
    void  WINAPI SetRepeat(BOOL bRepeat);
    DWORD WINAPI UpdateConfig(void *pvReserved){return 0;}//設定が変更されたら呼ばれる
};
