/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
#ifndef VIEWCONTAINER_H
#define VIEWCONTAINER_H

#include <jni.h>
#include <windows.h>
#include <manipulations.h>
#include <memory>

class GlassView;

class ViewContainer {
    private:
        GlassView * m_view;
        BOOL m_bTrackingMouse;
        HKL m_kbLayout;
        UINT m_codePage;
        LANGID m_idLang;

        std::auto_ptr<IDropTarget> m_spDropTarget;

        IManipulationProcessor*             m_manipProc;
        IInertiaProcessor*                  m_inertiaProc;
        _IManipulationEvents*               m_manipEventSink;
        jclass                              m_gestureSupportCls;

        void WmImeComposition(HWND hwnd, WPARAM wParam, LPARAM lParam);
        void WmImeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam);
        void SendInputMethodEvent(jstring text,
            int cClause, int* rgClauseBoundary,
            int cAttrBlock, int* rgAttrBoundary, BYTE *rgAttrValue,
            int commitedTextLength, int caretPos, int visiblePos);
        void GetCandidatePos(RECT* curPos);

    protected:
        void HandleViewMenuEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewInputLangChange(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewPaintEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewSizeEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewKeyEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewTypedEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        BOOL HandleViewMouseEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        BOOL HandleViewInputMethodEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        void HandleViewTouchEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    
        virtual void HandleViewTimerEvent(HWND hwnd, UINT_PTR timerID);

        void InitDropTarget(HWND hwnd);
        void ReleaseDropTarget();

        void InitManipProcessor(HWND hwnd);
        void ReleaseManipProcessor();

    private:
        ViewContainer(const ViewContainer&);
        ViewContainer& operator = (const ViewContainer&);
    
    public:
        enum {
            IDT_GLASS_ANIMATION_ENTER = 0x101,
            IDT_GLASS_ANIMATION_EXIT,
            IDT_GLASS_INERTIAPROCESSOR,
        };
        
        ViewContainer();

        inline GlassView * GetGlassView() const { return m_view; }
        inline void SetGlassView(GlassView * view) { m_view = view; }
        inline LANGID GetInputLanguage() { return m_idLang; }

        jobject GetView();

        void ResetMouseTracking(HWND hwnd);

        void NotifyViewSize(HWND hwnd);
        
        void NotifyGesturePerformed(HWND hWnd, 
            bool isDirect, bool isInertia,
            FLOAT x, FLOAT y, 
            FLOAT deltaX, FLOAT deltaY,
            FLOAT scaleDelta, FLOAT expansionDelta, FLOAT rotationDelta,
            FLOAT cumulativeDeltaX, FLOAT cumulativeDeltaY,
            FLOAT cumulativeScale, FLOAT cumulativeExpansion, FLOAT cumulativeRotation);
        
        void StartTouchInputInertia(HWND hwnd);
        void StopTouchInputInertia(HWND hwnd);
};

#endif // VIEWCONTAINER_H

