/***************************************************************************
 *                          Zanoza Modeler v2.x                            *
 *      This is unpublished propietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                Copyright (c) 2002-2003 Zanoza Software.                 *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler 2.x IViewport layers support helper
 *--------------------------------------------------------------------------
 * @histroy: 02.04.2003. Created
 */
#ifndef viewportlayershelper_h_included
#define viewportlayershelper_h_included

#include <zmodeler.h>
#include <core/ui/IVisualizationViewportLayer.h>
#include <core/events/IMouseEventHandler.h>
#include <core/events/IKeyboardEventHandler.h>
#include <core/events/IHitTestEventHandler.h>
#include <core/events/IViewEventHandler.h>
#include <helpers/layout.h>
#include <helpers/status.h>

namespace core
{
  namespace ui
  {
    //-------------------------------------------------------
    struct tLayerInfo
    {
      ZPtr<core::ui::IViewportLayer>                m_pLayer;
      ZPtr<core::ui::IVisualizationViewportLayer>   m_pVisLayer;
      ZPtr<core::events::IKeyboardEventHandler>     m_pKeybdHandler;
      ZPtr<core::events::IMouseEventHandler>        m_pMouseHandler;
      ZPtr<core::events::IHitTestEventHandler>      m_pHitTester;
      bool operator == (const struct tLayerInfo& info) const
      {
        return  (m_pLayer.m_p == info.m_pLayer.m_p) &&
                (m_pVisLayer.m_p == info.m_pVisLayer.m_p) &&
                (m_pMouseHandler.m_p == info.m_pMouseHandler.m_p) &&
                (m_pKeybdHandler.m_p == info.m_pKeybdHandler.m_p) &&
                (m_pHitTester.m_p == info.m_pHitTester.m_p);
      }
    };
    typedef ZCollection<tLayerInfo>   tLayersCollection;

    //------------------------------------------------------------------
    //
    // @Description : CLayersCollection class
    // @Purpose     : simplifies storing and managing viewport layers
    //
    //------------------------------------------------------------------
    class DLL_LINKAGE CLayersCollection : public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CLayersCollection)
    public:
      CLayersCollection();
      ~CLayersCollection();

    //
    // operations:
    //
    public:
      ZRESULT addLayer(core::ui::IViewportLayer* pLayer);
      ZRESULT getCollection(core::ui::CViewportLayerCol** ppCol);
      ZRESULT setFromCollection(core::ui::CViewportLayerCol* pCol);
    //
    // rendering
    //
      ZRESULT onRedraw(core::ui::IViewport* pVPort);
      ZRESULT onClose(core::ui::IViewport* pVPort);
    //-----------------------
    // IMouseEventHandler
    //-----------------------
      ZRESULT onLButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onLButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onMouseMove(DWORD nFlags, ZPoint& loc, ZPoint& offset, DWORD& nRetFlags);
      ZRESULT onRButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onRButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onMButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onMButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
      ZRESULT onMouseWheel(DWORD nFlags, ZPoint& loc, short zDelta, DWORD& nRetFlags);

    //-----------------------
    // IHitTestEventHandler
    //-----------------------
      ZRESULT onHitTest(ZPoint& pt, DWORD nFlags, long& nHitCode, DWORD& nRetFlags);
      ZRESULT onButton(ZPoint& pt, DWORD nPress, DWORD nRelease, DWORD& nRetFlags);

    //-----------------------
    // IKeyboardEventHandler
    //-----------------------
      ZRESULT onKeyUp(DWORD nKey, DWORD nFlags, DWORD& nRetFlags);
      ZRESULT onKeyDown(DWORD nKey, DWORD nFlags, DWORD& nRetFlags);

    //
    // data members;
    //
    private:
      tLayersCollection   m_LayersCol;

    };//class

    //-----------------------------------------------------
    //
    //    @Description: Base class.
    //    @Purpose    : Used for derivation of visual
    //                  viewport layers.
    //-----------------------------------------------------
    class DLL_LINKAGE CVisualViewportLayer :  public core::tools::CViewTool,
                                              public core::ui::IVisualizationViewportLayer
    {
      public:
        INTERFACE_DECLAREMAP(CVisualViewportLayer)
      public:
        CVisualViewportLayer();
        virtual ~CVisualViewportLayer(){}

      public:
      //-----------------------
      // IViewLayout
      //-----------------------
        virtual ZRESULT deploy(core::ui::IView* pView);

      public:
      //-----------------------
      // IVisualizationViewportLayer
      //-----------------------
        virtual ZRESULT getPriority(core::ePriority& prior);
        virtual ZRESULT setPriority(core::ePriority prior);
        virtual ZRESULT redraw(core::ui::IViewport* pViewport);
        virtual ZRESULT getSubLayers(CViewportLayerCol** ppCol);
        virtual ZRESULT setSubLayers(CViewportLayerCol* pCol);
        virtual ZRESULT onCloseViewport(core::ui::IViewport* pVPort) { return ZRESULT_OK; }

      public:
      //-----------------------
      // IStatus
      //-----------------------
        virtual ZRESULT getStatus(DWORD& nBits)
          { return DELIGATE(m_pStatus)getStatus(nBits); }
        virtual ZRESULT setStatus(DWORD nBits)
          { return DELIGATE(m_pStatus)setStatus(nBits); }
        virtual ZRESULT changeStatus(DWORD nAdd, DWORD nRemove)
          { return DELIGATE(m_pStatus)changeStatus(nAdd, nRemove); }
        virtual ZRESULT checkStatus(DWORD nBit)
          { return DELIGATE(m_pStatus)checkStatus(nBit); }

      public:
      //-----------------------
      // data members:
      //-----------------------
        ZPtr<core::CStatus>       m_pStatus;
        CLayersCollection         m_SubLayers;
        core::ePriority           m_Priority;
    };//class

    //-----------------------------------------------------
    //
    //    @Description: Base class for functional layers
    //    @Purpose    : Used for derivation of functional
    //                  viewport layers.
    //-----------------------------------------------------
    class DLL_LINKAGE CFunctionalViewportLayer :  public core::tools::CViewTool,
                                                  public core::ui::IViewportLayer,
                                                  public core::events::IMouseEventHandler,
                                                  public core::events::IKeyboardEventHandler
    {
      public:
        INTERFACE_DECLAREMAP(CFunctionalViewportLayer)
      public:
        CFunctionalViewportLayer();
        virtual ~CFunctionalViewportLayer(){}

      public:
      //-----------------------
      // IViewLayout
      //-----------------------
        virtual ZRESULT deploy(core::ui::IView* pView);

      public:
      //-----------------------
      // IViewportLayer
      //-----------------------
        virtual ZRESULT getPriority(core::ePriority& prior);
        virtual ZRESULT setPriority(core::ePriority prior);
        virtual ZRESULT getSubLayers(CViewportLayerCol** ppCol);
        virtual ZRESULT setSubLayers(CViewportLayerCol* pCol);
        virtual ZRESULT onCloseViewport(core::ui::IViewport* pVPort) { return ZRESULT_OK; }

      public:
      //-----------------------
      // IStatus
      //-----------------------
        virtual ZRESULT getStatus(DWORD& nBits)
          { return DELIGATE(m_pStatus)getStatus(nBits); }
        virtual ZRESULT setStatus(DWORD nBits)
          { return DELIGATE(m_pStatus)setStatus(nBits); }
        virtual ZRESULT changeStatus(DWORD nAdd, DWORD nRemove)
          { return DELIGATE(m_pStatus)changeStatus(nAdd, nRemove); }
        virtual ZRESULT checkStatus(DWORD nBit)
          { return DELIGATE(m_pStatus)checkStatus(nBit); }

      public:
      //-----------------------
      // IMouseEventHandler
      //-----------------------
        virtual ZRESULT supportEvent(core::events::tEvent nEvent) const;
        virtual ZRESULT onLButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onLButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onMouseMove(DWORD nFlags, ZPoint& loc, ZPoint& offset, DWORD& nRetFlags);
        virtual ZRESULT onRButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onRButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onMButtonDown(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onMButtonUp(DWORD nFlags, ZPoint& loc, DWORD& nRetFlags);
        virtual ZRESULT onMouseWheel(DWORD nFlags, ZPoint& loc, short zDelta, DWORD& nRetFlags);

      public:
      //-----------------------
      // IKeyboardEventHandler
      //-----------------------
        virtual ZRESULT onKeyUp(DWORD nKey, DWORD nFlags, DWORD& nRetFlags);
        virtual ZRESULT onKeyDown(DWORD nKey, DWORD nFlags, DWORD& nRetFlags);

      public:
      //-----------------------
      // data members:
      //-----------------------
        ZPtr<core::CStatus>       m_pStatus;
        CLayersCollection         m_SubLayers;
        core::ePriority           m_Priority;
    };//class

  };//ui
};//core

#endif //viewportlayershelper_h_included



