/***************************************************************************
 *                          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 Zanoza Software.                   *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler 2.x tools layout helper classes
 *--------------------------------------------------------------------------
 * @histroy: 03.01.2003. Created
 */
#ifndef layouthelper_h_included
#define layouthelper_h_included

#include <core/IConfiguration.h>
#include <core/INamed.h>
#include <core/tools/ITool.h>
#include <core/layout/IContextMenuLayout.h>
#include <core/layout/ICustomMenuLayoutView.h>
#include <core/layout/IToolBarLayout.h>
#include <core/layout/ICommandBarLayout.h>
#include <core/layout/IFloaterLayout.h>
#include <core/layout/INotifyChildDialog.h>
#include <core/layout/IViewLayout.h>
#include <core/layout/IStartupLayout.h>
#include <core/ui/ICursorSupport.h>
#include <core/ui/IVisualControl.h>

namespace core
{
  namespace tools
  {
    //forward:
    class CZMCommandBarLayout;
    class CZMMenuLayout;
    class CZMCommandBarChildDialog;


    //-----------------------------------------------------
    //
    // CZMToolHelper class provides basic implementation
    // of ITool interface. The class can't be used as is and
    // aimed for derieving your own classes.
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMToolHelper : public ITool, public INamed
    {
    public:
      CZMToolHelper(){}
      virtual ~CZMToolHelper(){}
    //-----------------------------
    //    ITool
    //-----------------------------
    public:
      virtual ZRESULT requires(DWORD& dwRequires) const;
      virtual ZRESULT getLayout(core::layout::ILayout** ppLayout)=0;
      virtual ZRESULT getLibrary(core::libs::ILibrary** ppLib);
      virtual ZRESULT setLibrary(core::libs::ILibrary*  pLib);
      virtual ZRESULT apply(IProcParams* pParams=NULL, DWORD* pRetVal=NULL);
      virtual ZRESULT done(IProcParams* pParams=NULL, DWORD* pRetVal=NULL) { return ZRESULT_FALSE; }
    //-----------------------------
    //    INamed
    //-----------------------------
      virtual ZRESULT getName(ZString& str);
      virtual ZRESULT setName(ZString str);
      virtual ZRESULT getTitle(ZString& str);
      virtual ZRESULT setTitle(ZString str);
      virtual ZRESULT getDescription(ZStringSeq& seqDesc);
      virtual ZRESULT setDescription(ZStringSeq& seqDesc);

    //-----------------------------
    //    implementation helpers
    //-----------------------------
    public:
      ZString                   m_strName;
      ZString                   m_strTitle;
      ZStringSeq                m_seqDesc;
      ZPtr<core::libs::ILibrary>  m_pLibrary;
    };

    //
    // class CCursorSupport simplifies work with cursors
    //
    class DLL_LINKAGE CCursorSupport : public core::ui::ICursorSupport
    {
    public:
      CCursorSupport();
      CCursorSupport( core::ui::eCursorResource curDef,
                      core::ui::eCursorResource curCtrl,
                      core::ui::eCursorResource curShift);
      CCursorSupport( DWORD dwCustomCursorID);
    //-----------------------------
    //    ICursorSupport
    //-----------------------------
    public:
      virtual ZRESULT getCursor(DWORD nFlags, HCURSOR& hCur);

    //-----------------------------
    //    data members
    //-----------------------------
    public:
      HCURSOR                   m_hcDef;
      HCURSOR                   m_hcCtrl;
      HCURSOR                   m_hcShift;
    };

    //-----------------------------------------------------
    //
    // CZMCommandBarLayout class provides basic implementation
    // of ITool interface. The class can't be used as is and
    // aimed for derieving your own classes.
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMCommandBarLayoutEx :
                    public core::layout::ICommandBarLayout,
                    public core::IConfiguration
    {
    public:
      CZMCommandBarLayoutEx(){}
      virtual ~CZMCommandBarLayoutEx(){}
    //-----------------------------
    //    ICommandBarLayout
    //-----------------------------
    public:
      virtual ZRESULT getGroup(core::layout::tCommandBarTab& group) const;
      virtual ZRESULT getBranch(ZStringSeq& branch) const;
      virtual ZRESULT getButtonKind(DWORD& kind) const;
      virtual ZRESULT onDeploy(core::ui::IControlBar* pBar);

    //-----------------------------
    //    IConfiguration
    //-----------------------------
    public:
      virtual ZRESULT getDialogs(core::layout::CChildDialogCol** ppDialogs)=0;

    //-----------------------------
    //  data members
    public:
      ZStringSeq              m_seqBranch;
    };


    //-----------------------------------------------------
    //
    // CZMChildDialog class provides basic implementation
    // of IChildDialog interface. The class can't be used
    // as is and aimed for derieving your own classes.
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMChildDialog :
                          public core::layout::IChildDialog
    {
    public:
      CZMChildDialog(){}
      virtual ~CZMChildDialog(){}
    public:
      //-----------------------------
      //  IDialog
      //-----------------------------
      ZRESULT getTemplate(HWND& hTemplate);

      //-----------------------------
      //  IChildDialog
      //-----------------------------
      ZRESULT init(HWND hwnd, HWND** hThis = NULL);
      ZRESULT getDialogTitle(ZString& strTitle);
      ZRESULT setDialogTitle(ZString strTitle);
      ZRESULT show(core::IProcParams* params);
      ZRESULT hide(core::IProcParams* params);
      ZRESULT isVisible();

      // accessors:
      void setDialog(CDialog* pDialog, bool bAutoDelete=true);
      CDialog*  getDialog();
    private:
      //data members:
      ZStdPtr<CDialog>        m_pDialog;
      ZStdOwnPtr<CDialog>     m_pOwnDialog;
      ZString                 m_strDialogTitle;
    };

    //-----------------------------------------------------
    //
    // CChildDialog incompletely implemented class for
    // acting with child dialogs. To use the class, derieve
    // your own class from this one and insert macro
    // CHILDDIALOG_IMPLEMENT (see below) in your class declaration
    //-----------------------------------------------------
    class DLL_LINKAGE CChildDialog :  public CDialog, 
                                      public core::layout::IChildDialog,
                                      public core::CErrorInfo
    {
    public:
      DECLARE_DYNCREATE(CChildDialog)
      INTERFACE_DECLAREMAP(CChildDialog)
    public:
      //-----------------------------
      //  constructors
      //-----------------------------
      CChildDialog();
      CChildDialog(LPCTSTR strTitle);
      virtual ~CChildDialog();
    public:
      //-----------------------------
      //  IDialog
      //-----------------------------
      ZRESULT getTemplate(HWND& hTemplate);

      //-----------------------------
      //  IChildDialog
      //-----------------------------
      ZRESULT init(HWND hwnd, HWND** hThis = NULL);
      ZRESULT getDialogTitle(ZString& strTitle);
      ZRESULT setDialogTitle(ZString strTitle);
      ZRESULT show(core::IProcParams* params);
      ZRESULT hide(core::IProcParams* params);
      ZRESULT isVisible();
    private:
      BOOL PreTranslateMessage(MSG* pMsg);//blocks Enter and Esc

    public:
      ZString       m_strDialogTitle;
    };
//--------------------------------------------------------------------
// CHILDDIALOG_IMPLEMENT(_theclass, _resource)
// macro implements required functions that have to be bind to the
// top-level (leftmost in derivation tree) class. e.g. your final class
//--------------------------------------------------------------------
#define CHILDDIALOG_IMPLEMENTONLY(_resource)                        \
    virtual ZRESULT init(HWND hwnd, HWND** hThis = NULL)            \
    {                                                               \
    if ((m_hWnd != 0) && (::GetParent(m_hWnd) != hwnd))             \
        return REPORT_ERROR(NULL, _T("Can't recreate dialog."));    \
      if (m_hWnd == 0)                                              \
      {                                                             \
        ZM_AUTO_HANDLE_SWITCH();                                    \
        if (!Create(_resource, CWnd::FromHandle(hwnd)))             \
          return ZRESULT_FAIL;                                      \
      }                                                             \
      if (NULL != hThis)                                            \
        (*hThis) = &m_hWnd;                                         \
      return ZRESULT_OK;                                            \
    }
#define CHILDDIALOG_IMPLEMENT(_theclass, _resource)                 \
    INTERFACE_OVERLOAD_INSTANCE_CREATOR(_theclass)                  \
    CHILDDIALOG_IMPLEMENTONLY(_resource)

    //-----------------------------------------------------
    //
    // CNotifyChildDialog incompletely implemented class for
    // acting with child dialogs. To use the class, derieve
    // your own class from this one and insert macro
    // CHILDDIALOG_IMPLEMENT (see below) in your class declaration
    //-----------------------------------------------------
    class DLL_LINKAGE CNotifyChildDialog :  public CDialog, 
                                            public core::layout::INotifyChildDialog,
                                            public core::CErrorInfo
    {
    public:
      DECLARE_DYNCREATE(CNotifyChildDialog)
      INTERFACE_DECLAREMAP(CNotifyChildDialog)
    public:
      //-----------------------------
      //  constructors
      //-----------------------------
      CNotifyChildDialog();
      CNotifyChildDialog(LPCTSTR strTitle);
      virtual ~CNotifyChildDialog();
    public:
      //-----------------------------
      //  IDialog
      //-----------------------------
      ZRESULT getTemplate(HWND& hTemplate);

      //-----------------------------
      //  IChildDialog
      //-----------------------------
      ZRESULT init(HWND hwnd, HWND** hThis = NULL);
      ZRESULT getDialogTitle(ZString& strTitle);
      ZRESULT setDialogTitle(ZString strTitle);
      ZRESULT show(core::IProcParams* params);
      ZRESULT hide(core::IProcParams* params);
      ZRESULT isVisible();

      //-----------------------------
      //  IChildDialog
      //-----------------------------
      virtual ZRESULT onShow(void);
      virtual ZRESULT onHide(void);
      virtual ZRESULT onOK(void);
      virtual ZRESULT onCancel(void);
      virtual ZRESULT onApply(void);

    public:
      ZString       m_strDialogTitle;
    };

    //----------------------------------------------------------
    // Startup tool helper class.
    //----------------------------------------------------------
    class DLL_LINKAGE CStartupToolHelper :  public CZMToolHelper,
                                            public layout::IStartupLayout
    {
    public:
      INTERFACE_DECLAREMAP(CStartupToolHelper)
    public:
      CStartupToolHelper();
      virtual ~CStartupToolHelper();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    public:
      //------------------------
      // IStartupLayout
      //------------------------
      virtual ZRESULT startup(void); //override this
    };

    //----------------------------------------------------------
    // Command Bar layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CCommandBarToolEx :
                              public CZMToolHelper,
                              public CZMCommandBarLayoutEx,
                              public CCursorSupport,
                              public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CCommandBarToolEx)
    public:
      CCommandBarToolEx();
      CCommandBarToolEx(core::ui::eCursorResource curDef,
                        core::ui::eCursorResource curCtrl,
                        core::ui::eCursorResource curShift);
      CCommandBarToolEx(core::ui::eCursorResource cursor);
      CCommandBarToolEx(DWORD dwCustomCursorID);
      CCommandBarToolEx(DWORD dwCursorDefID, DWORD dwCursorCtrlID, DWORD dwCursorShiftID);
      virtual ~CCommandBarToolEx();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getDialogs(core::layout::CChildDialogCol** ppDialogs);
      ZRESULT getLayout(core::layout::ILayout** ppLayout);

    public:
      //data members:
      ZPtr<core::layout::CChildDialogCol>   m_pDialogs;
    };




    //-----------------------------------------------------
    //
    // CZMMenuLayoutEx class provides basic implementation
    // of IMenuLayout interface. The class can't be used as is and
    // aimed for derieving your own classes.
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMMenuLayoutEx :
                      public core::layout::IMenuLayout,
                      public core::layout::ICustomMenuLayoutView
    {
    public:
      CZMMenuLayoutEx() : m_nImageIndex(-1) {}
      virtual  ~CZMMenuLayoutEx() {}
    //-----------------------------
    //    IMenuLayout
    //-----------------------------
    public:
      virtual ZRESULT getBranch(ZStringSeq& branch) const;
      virtual ZRESULT getItemKind(DWORD& kind) const;
      virtual ZRESULT onDeploy(CMenu* pMenu, DWORD dwID);
    //-----------------------------
    //    ICustomLayoutView
    //-----------------------------
    public:
      virtual ZRESULT getImages(CImageList** images, long& nItem) const;
      virtual ZRESULT setImages(CImageList* images, long nItem);
    //-----------------------------
    //    ICustomMenuLayoutView
    //-----------------------------
    public:
      virtual ZRESULT setBranch(ZStringSeq seqBranch);
      virtual ZRESULT setHotKey(ZString strText);

    //-----------------------------
    //  data members
    public:
      ZStringSeq                    m_seqBranch;
      ZString                       m_strHotKey;
      ZStdPtr<CImageList>           m_pImages;
      long                          m_nImageIndex;
    };

    //-----------------------------------------------------
    //
    // CZMContextMenuLayoutEx class provides basic implementation
    // of IContextMenuLayout interface. The class can't be used as is and
    // aimed for derieving your own classes.
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMContextMenuLayoutEx :
                      public core::layout::IContextMenuLayout,
                      public core::layout::ICustomMenuLayoutView
    {
    public:
      CZMContextMenuLayoutEx(){}
      virtual ~CZMContextMenuLayoutEx(){}
    //-----------------------------
    //  IMenuLayout, IContextMenuLayout
    //-----------------------------
    public:
      virtual ZRESULT getBranch(ZStringSeq& branch) const;
      virtual ZRESULT getItemKind(DWORD& kind) const;
      virtual ZRESULT onDeploy(CMenu* pMenu, DWORD dwID);
      virtual ZRESULT queryLayout(scene::INode* pNode, core::eLevel level, core::ui::IViewport* pViewport)
        { return ZRESULT_FALSE; } //overload this function
    //-----------------------------
    //    ICustomLayoutView
    //-----------------------------
    public:
      virtual ZRESULT getImages(CImageList** images, long& nItem) const;
      virtual ZRESULT setImages(CImageList* images, long nItem);
    //-----------------------------
    //    ICustomMenuLayoutView
    //-----------------------------
    public:
      virtual ZRESULT setBranch(ZStringSeq seqBranch);
      virtual ZRESULT setHotKey(ZString strText);

    //-----------------------------
    //  data members
    public:
      ZStringSeq                    m_seqBranch;
      ZString                       m_strHotKey;
      ZStdPtr<CImageList>           m_pImages;
      long                          m_nImageIndex;
    };


    //----------------------------------------------------------
    // Menu layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CMenuToolEx :
                              public CZMToolHelper,
                              public CZMMenuLayoutEx,
                              public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CMenuToolEx)
    public:
      CMenuToolEx();
      virtual ~CMenuToolEx();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    };

    //----------------------------------------------------------
    // Contect Menu layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CContextMenuToolEx :
                              public CZMToolHelper,
                              public CZMContextMenuLayoutEx,
                              public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CContextMenuToolEx)
    public:
      CContextMenuToolEx();
      virtual ~CContextMenuToolEx();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    };

    //-----------------------------------------------------
    //
    // CZMToolBarLayoutEx class provides basic implementation
    // of IToolBarLayout interface. The class can't be used 
    // as is and aimed for derieving your own classes and 
    // overriding the following operations:
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMToolBarLayoutEx :
                      public core::layout::IToolBarLayout,
                      public core::layout::ICustomLayoutView 
    {
    public:
      CZMToolBarLayoutEx(){}
      virtual ~CZMToolBarLayoutEx(){}
    //-----------------------------
    //    IToolBarLayout
    //-----------------------------
    public:
      virtual ZRESULT getToolBarCaption(ZString& caption) const;
      virtual ZRESULT getItemKind(DWORD& kind) const;
      virtual ZRESULT getVariationName(ZString& strName);
      virtual ZRESULT onDeploy(CToolBar* pToolBar, DWORD dwID);
      virtual ZRESULT deploy(core::ui::IToolBar* pToolBar);
    //-----------------------------
    //    ICustomLayoutView
    //-----------------------------
    public:
      virtual ZRESULT getImages(CImageList** images, long& nItem) const;
      virtual ZRESULT setImages(CImageList* images, long nItem);

    //-----------------------------
    //  data members
    public:
      ZString                       m_strCaption;
      ZStdPtr<CImageList>           m_pImages;
      long                          m_nImageIndex;
    };


    //----------------------------------------------------------
    // ToolBar layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CToolBarToolEx :
                              public CZMToolHelper,
                              public CZMToolBarLayoutEx,
                              public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CToolBarToolEx)
    public:
      CToolBarToolEx();
      virtual ~CToolBarToolEx();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    };


    //-----------------------------------------------------
    //
    // CZMFloaterLayoutEx class provides basic implementation
    // of IFloaterLayout interface. The class can't be used 
    // as is and aimed for derieving your own classes and 
    // overriding the following operations:
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMFloaterLayoutEx :
                      public CZMChildDialog,
                      public core::layout::IFloaterLayout,
                      public core::CErrorInfo
    {
    public:
      CZMFloaterLayoutEx(){}
      virtual ~CZMFloaterLayoutEx(){}
    //-----------------------------
    //    IFloaterLayout
    //-----------------------------
    public:
      virtual ZRESULT getDialogBar(core::ui::IDialogBar** ppBar);
      virtual ZRESULT deploy(core::ui::IDialogBar** ppBar)=0;

    //-----------------------------
    //  data members
    public:
      ZPtr<core::ui::IDialogBar>    m_pDialogBar;
      bool                          m_bDockable;
      bool                          m_bSizeable;
    };


    //----------------------------------------------------------
    // Floater layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CFloaterToolEx :
                              public CZMFloaterLayoutEx,
                              public CZMToolHelper
    {
    public:
      INTERFACE_DECLAREMAP(CFloaterToolEx)
    public:
      CFloaterToolEx();
      virtual ~CFloaterToolEx();

      virtual ZRESULT deploy(core::ui::IDialogBar** ppBar);
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    };

    //----------------------------------------------------------
    // Floater layout class with main menu support
    //----------------------------------------------------------
    class DLL_LINKAGE CFloaterMenuTool :
                              public CFloaterToolEx,
                              public CZMMenuLayoutEx
    {
    public:
      INTERFACE_DECLAREMAP(CFloaterMenuTool)
    public:
      CFloaterMenuTool();
      virtual ~CFloaterMenuTool();
    };


    //-----------------------------------------------------
    //
    // CZMViewLayout class provides basic implementation
    // of IViewLayout interface. The class can't be used 
    // as is and aimed for derieving your own classes and 
    // overriding the following operations:
    //
    //-----------------------------------------------------
    class DLL_LINKAGE CZMViewLayout :
                      public core::layout::IViewLayout
    {
    public:
      CZMViewLayout(){}
      virtual ~CZMViewLayout(){}
    //-----------------------------
    //    IViewLayout
    //-----------------------------
    public:
      virtual ZRESULT deploy(core::ui::IView* pView);

    };


    //----------------------------------------------------------
    // Viewport layout class.
    //----------------------------------------------------------
    class DLL_LINKAGE CViewTool : public CZMToolHelper,
                                  public CZMViewLayout,
                                  public core::CErrorInfo
    {
    public:
      INTERFACE_DECLAREMAP(CViewTool)
    public:
      CViewTool();
      virtual ~CViewTool();
      //------------------------
      // default implementation
      //------------------------
      ZRESULT getLayout(core::layout::ILayout** ppLayout);
    };

    //----------------------------------------------------------
    // Viewport layout class with menu support
    //----------------------------------------------------------
    class DLL_LINKAGE CViewMenuTool : public CViewTool,
                                      public CZMMenuLayoutEx
    {
    public:
      INTERFACE_DECLAREMAP(CViewMenuTool)
    public:
      CViewMenuTool();
      virtual ~CViewMenuTool();
    };

    //----------------------------------------------------------
    // Viewport menu only support
    //----------------------------------------------------------
    class DLL_LINKAGE CViewMenuOnlyTool : public CViewTool,
                                          public CZMMenuLayoutEx,
                                          public core::ui::IVisualControl
    {
    public:
      INTERFACE_DECLAREMAP(CViewMenuOnlyTool)
    public:
      CViewMenuOnlyTool();
      virtual ~CViewMenuOnlyTool();
    public:
      //overloaded:
      virtual ZRESULT deploy(core::ui::IView* pView);
      //------------------------
      //  IVisualControl
      //------------------------
      virtual ZRESULT redrawControl(CDC* pDC);
      virtual ZRESULT showControl(CDC* pDC, core::ui::IView* pOwner);
      virtual ZRESULT getMinimalRect(ZRect& rect);
      virtual ZRESULT setLayoutRect(ZRect& rect);
      virtual ZRESULT getLayoutRect(ZRect& rect);
      virtual ZRESULT canStretchControl(void);
      virtual ZRESULT getControlPriority(core::ePriority& prior);
    };

  };//tools
};//core



//-------------------------------------------------------
// @name : IMPLEMENT_TREE_NAVIGATOR
// Implements basic tree-navigation interface.
// @param _class                         : classname of the nodes
//-------------------------------------------------------
#define IMPLEMENT_TREE_NAVIGATOR(_class)                                \
    public:                                                             \
      ZRESULT getRoot(ITreeNavigator** ppRoot)                          \
      {                                                                 \
        if (!ppRoot)                                                    \
          return ZRESULT_INVALID_ARG;                                   \
        if (m_pParent != NULL)                                          \
          return m_pParent->getRoot(ppRoot);                            \
        (*ppRoot) = this;                                               \
        (*ppRoot)->AddRef();                                            \
        return ZRESULT_OK;                                              \
      }                                                                 \
      ZRESULT getParent(ITreeNavigator** ppParent)                      \
      {                                                                 \
        if (!ppParent)                                                  \
          return ZRESULT_INVALID_ARG;                                   \
        (*ppParent) = m_pParent;                                        \
        if (*ppParent)                                                  \
          (*ppParent)->AddRef();                                        \
        return (*ppParent) ? ZRESULT_OK : ZRESULT_FALSE;                \
      }                                                                 \
      ZRESULT killSubs(bool bForceDelete=false)                         \
      {                                                                 \
        if (bForceDelete)                                               \
        {                                                               \
          delete m_pSub.m_p;                                            \
          m_pSub.m_p = NULL;                                            \
        }                                                               \
        else                                                            \
          m_pSub = NULL;                                                \
        return ZRESULT_OK;                                              \
      }                                                                 \
      ZRESULT getSub(ITreeNavigator** ppSub)                            \
      {                                                                 \
        if (NULL == ppSub)                                              \
          return ZRESULT_INVALID_ARG;                                   \
        (*ppSub) = m_pSub;                                              \
        if (*ppSub)                                                     \
          (*ppSub)->AddRef();                                           \
        return (*ppSub) ? ZRESULT_OK : ZRESULT_FALSE;                   \
      }                                                                 \
      ZRESULT getNext(ITreeNavigator** ppNext)                          \
      {                                                                 \
        if (NULL == ppNext)                                             \
          return ZRESULT_INVALID_ARG;                                   \
        (*ppNext) = m_pNext;                                            \
        if (*ppNext)                                                    \
          (*ppNext)->AddRef();                                          \
        return (*ppNext) ? ZRESULT_OK : ZRESULT_FALSE;                  \
      }                                                                 \
    public:                                                             \
      ZStdPtr<_class>  m_pParent;                                       \
      ZPtr<_class>    m_pSub;                                           \
      ZPtr<_class>    m_pNext;


#define INTERACTIVE_TOOL_DELEGATE(_base)                                \
      virtual ZRESULT getLayout(core::layout::ILayout** ppLayout)       \
      { return _base::getLayout(ppLayout); }                            \
      virtual ZRESULT getLibrary(core::libs::ILibrary** ppLib)          \
      { return _base::getLibrary(ppLib); }                              \
      virtual ZRESULT setLibrary(core::libs::ILibrary* pLib)            \
      { return _base::setLibrary(pLib); }

#endif //layouthelper_h_included
