/**
* @file XTPMDIWndTab.h
*
* @copyright
* (c) 1998-2025 Codejock Software, All Rights Reserved.
*
* This source file is the property of Codejock Software and must not be
* redistributed by any means without the explicit written permission of
* Codejock Software.
*
* The use of this source code is governed by the terms and conditions specified
* in the Toolkit Pro license agreement. Codejock Software grants you, as a
* single software developer, the limited right to use this software on one
* computer only.
*
* Contact Information:
* support@codejock.com
* http://www.codejock.com
*
*/
/** @cond */
#if !defined(__XTPMDIWNDTAB_H__)
# define __XTPMDIWNDTAB_H__
/** @endcond */
# if _MSC_VER > 1000
# pragma once
# endif // _MSC_VER > 1000
# include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h"
/**
* forwards
*/
class CXTPMDIWndTab;
/**
* @brief
* CXTPMDIClientWnd is a CWnd derived helper class for the CXTPMDIWndTab tab
* control. This class routes messages sent to the client window back
* to the tab control.
*/
class _XTP_EXT_CLASS CXTPMDIClientWnd : public CWnd
{
public:
/**
* @brief
* Constructs a CXTPMDIClientWnd object.
* @param pMDIWndTab Pointer to a CXTPMDITabWnd object.
*/
CXTPMDIClientWnd(CXTPMDIWndTab* pMDIWndTab);
/**
* @brief
* Destroys a CXTPMDIClientWnd object, handles cleanup and deallocation
*/
virtual ~CXTPMDIClientWnd();
public:
/**
* @brief
* This member function will set the size of the gap between the client
* area and the tab control.
* @param iSize Amount, in pixels, of gap between the tab control and the client.
*/
void SetBorderGap(int iSize);
protected:
/** @cond */
DECLARE_MESSAGE_MAP()
//{{AFX_VIRTUAL(CXTPMDIClientWnd)
virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder);
//}}AFX_VIRTUAL
//{{AFX_MSG(CXTPMDIClientWnd)
afx_msg LRESULT OnMDICreate(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMDIDestroy(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMDIActivate(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
/** @endcond */
protected:
int m_iBorderGap; /**< Amount, in pixels, between the client and the tab control. */
CXTPMDIWndTab* m_pMDIWndTab; /**< Pointer to the MDI tab control. */
};
//////////////////////////////////////////////////////////////////////
/** @cond */
AFX_INLINE void CXTPMDIClientWnd::SetBorderGap(int iBorderGap)
{
m_iBorderGap = iBorderGap;
}
DECLARE_TABCTRL_BASE(CXTPMDIWndTabBase, CTabCtrl, CXTPTabBase)
/** @endcond */
/**
* @brief
* The CXTPMDIWndTab class is used for creating a tabbed MDI document
* interface.
* @details
* CXTPMDIWndTab is derived from CTabCtrl and CXTPTabCtrlBase and is
* used to create a tab control for a multiple document interface
* (MDI) application.
* Example:
* The following example demonstrates the use of CXTPMDIWndTab:
*
* // Install the MDI tab window.
* m_wndMDITabWindow.Install(this, NULL, TRUE);
* m_wndMDITabWindow.SetBorderGap(1);
*
*/
class _XTP_EXT_CLASS CXTPMDIWndTab : public CXTPMDIWndTabBase
{
/** @cond */
DECLARE_DYNAMIC(CXTPMDIWndTab)
/** @endcond */
/**
* @brief
* The MDICHILD structure is used by the CXTPMDIWndTab class for
* maintaining information on each window in a MDI tab.
* @see
* CMDIChildList, CXTPMDIWndTab
*/
struct MDICHILD
{
int iItem; /**< Index of the item in the tab control. */
HWND hWnd; /**< Window handle of the tab item. */
CString strItem; /**< Tab label. */
};
/**
* @brief
* List for maintaining MDICHILD structures.
* @details
* CList definition used by the CXTPMDIWndTab class to maintain a
* list of MDICHILD structures representing each MDI child item in
* the tab control.
* @see
* CXTPMDIWndTab, MDICHILD
*/
typedef CList CMDIChildList;
/**
* @brief
* Map for maintaining HWND to HICON handle relationships.
* @details
* CMap definition used by the CXTPMDIWndTab class to maintain
* a list of HWND to HICON handle relationships to map a MDI child
* window with the tab icon displayed.
* @see
* CXTPMDIWndTab
*/
typedef CMap CIconWndMap;
/**
* @brief
* Map for maintaining HWND to CString object relationships.
* @details
* CMap definition used by the CXTPMDIWndTab class to maintain
* a list of HWND to CString object relationships to map a MDI child
* window with the tab label displayed.
* @see
* CXTPMDIWndTab
*/
typedef CMap CStringMap;
public:
/**
* @brief
* Constructs a CXTPMDIWndTab object.
*/
CXTPMDIWndTab();
/**
* @brief
* Destroys a CXTPMDIWndTab object, handles cleanup and deallocation.
*/
virtual ~CXTPMDIWndTab();
public:
/**
* @brief
* Call this member function to set the icon for the tab item specified
* by 'iIndex'.
* @param iIndex Zero-based index of the tab to set the tab icon for.
* @param hIcon Reference to a HICON handle that represents the tab icon.
* @return
* true if successful, otherwise false.
*/
bool SetTabIcon(int iIndex, HICON& hIcon);
/**
* @brief
* Call this member function to set the icon for the tab item specified
* by 'iIndex'.
* @param hChildWnd Valid HWND of the MDI child window to set the tab icon for.
* @param hIcon Reference to a HICON handle that represents the tab icon.
* @return
* true if successful, otherwise false.
*/
bool SetTabIcon(HWND hChildWnd, HICON& hIcon);
/**
* @brief
* Call this member function to set the label for the tab item specified
* by 'iIndex'.
* @param iIndex Zero-based index of the tab to set the tab text for.
* @param strLabel Reference to a CString object that represents the tab label.
* @return
* true if successful, otherwise false.
*/
bool SetTabLabel(int iIndex, CString& strLabel);
/**
* @brief
* Call this member function to set the label for the tab item specified
* by 'iIndex'.
* @param hChildWnd Valid HWND of the MDI child window to set the tab text for.
* @param strLabel Reference to a CString object that represents the tab label.
* @return
* true if successful, otherwise false.
*/
bool SetTabLabel(HWND hChildWnd, CString& strLabel);
/**
* @brief
* This member function will install the MDI tab views with your application.
* @param pMDIFrameWnd Pointer to the parent MDI frame window.
* @param dwStyle Style for the tab control. It can be any of the TCS_ values.
* @param bNoIcons TRUE to not display icons.
* @return
* TRUE if successful, otherwise returns FALSE.
*/
virtual BOOL Install(CMDIFrameWnd* pMDIFrameWnd, DWORD dwStyle = TCS_BOTTOM | TCS_HOTTRACK,
BOOL bNoIcons = TRUE);
/**
* @brief
* This member function will uninstall the MDI tab views from your application.
* @return
* TRUE if successful, otherwise FALSE.
*/
virtual BOOL UnInstall();
/**
* @brief
* Call this member function to retrieve the tab index from the current
* cursor position.
* @param point Pointer to a CPoint object that contains the cursor screen
* coordinates. Use default for the current cursor position.
* @return
* The zero-based index of the tab, or -1 if no tab is at the specified point.
*/
int TabFromPoint(CPoint point) const;
/**
* @brief
* This member function will retrieve a pointer to the child frame associated
* with the tab item.
* @param iIndex Index of the tab control. If -1, then the tab under the mouse when
* the last right click was performed will be used.
* @return
* A CWnd object if successful, otherwise NULL.
*/
CMDIChildWnd* GetFrameWnd(int iIndex = -1) const;
/**
* @brief
* This member function will retrieve a pointer to the child frame associated
* with the tab item.
* @param point CPoint object that represents the cursor position.
* @return
* A CWnd object if successful, otherwise NULL.
*/
CMDIChildWnd* GetFrameWnd(CPoint point) const;
/**
* @brief
* This member function is used to set the resource ID for the pop-up menu
* used by the tab control.
* @param popupMenuID ID for the tab control pop-up menu.
* @param nPos Index position in the menu resource.
* @param nDefCmd ID of the default menu command. Will display bold.
*/
void SetMenuID(UINT popupMenuID, int nPos = 0, UINT nDefCmd = (UINT)-1);
/**
* @brief
* This member function will set the size of the gap between the client
* area and the tab control.
* @param iSize Amount, in pixels, of gap between the tab control and the client.
*/
void SetBorderGap(int iSize);
/**
* @brief
* This member function will get the text for the specified MDI child
* window.
* @param hWnd Handle to a valid CMDIChildWnd object.
* @return
* A const CString object that represents the document title.
*/
CString GetChildWndText(HWND hWnd) const;
protected:
/**
* @brief
* This member function is called by the CXTPMDIWndTab class to
* perform initialization when the window is created or sub-classed.
* @return
* TRUE if the window was successfully initialized, otherwise FALSE.
*/
virtual BOOL Init();
/**
* @brief
* This member function is called to initialize the font for the tab control
* associated with this view.
*/
virtual void InitializeFont();
/**
* @brief
* This member function is called to insert a child frame into the MDI
* tab control.
* @param pChildFrame A pointer to a valid child frame window.
* @param bRecalcLayout TRUE to force the MDI frame window to recalculate the layout.
*/
virtual void InsertTabWnd(CMDIChildWnd* pChildFrame, BOOL bRecalcLayout = TRUE);
/**
* @brief
* This member function is called by the tab control to ensure that the current
* selection matches the active document.
* @return
* FALSE if there is no active document, otherwise TRUE.
*/
BOOL RefreshActiveSel();
/**
* @brief
* This member function is called by the tab control to ensure that the tab
* labels match their corresponding views.
*/
void RefreshTabLabels();
/**
* @brief
* This member function is called by the tab control to ensure that the stored
* indexes match their corresponding tab indexes.
*/
void RefreshIndexes();
/**
* @brief
* Called when a WM_MDICREATE message is sent to a multiple-document
* interface (MDI) client window to create an MDI child window.
* @param hWnd Handle to the destination control.
*/
virtual void OnMDICreate(HWND hWnd);
/**
* @brief
* Called when a WM_MDIDESTROY message is sent to a multiple-document
* interface (MDI) client window to close an MDI child window.
* @param hWnd Handle to the destination control.
*/
virtual void OnMDIDestroy(HWND hWnd);
/**
* @brief
* Called when a WM_MDIACTIVATE message is sent to a multiple-document
* interface (MDI) client window to instruct the client window
* to activate a different MDI child window.
* @param hWnd Handle to the destination control.
*/
virtual void OnMDIActivate(HWND hWnd);
/**
* @brief
* Called to refresh the tab labels and frame window layout.
* @param bDelayRecalc TRUE to call DelayRecalcLayout for the parent frame.
*/
virtual void RecalcLayout(BOOL bDelayRecalc);
protected:
/** @cond */
DECLARE_MESSAGE_MAP()
//{{AFX_MSG(CXTPMDIWndTab)
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg void OnNcPaint();
afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDestroy();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnIdleUpdateCmdUI();
afx_msg void OnTabClose();
//}}AFX_MSG
/** @endcond */
protected:
int m_iBorderGap; /**< Amount, in pixels, between the client and the tab control. */
int m_iHitTest; /**< Index of the tab that received a right click. */
int m_nPos; /**< Index of the pop-up menu contained in the menu. */
UINT m_nDefCmd; /**< Command ID of the default menu item for the pop-up menu. */
UINT m_popupMenuID; /**< Pop-up menu resource ID. */
HWND m_hActiveChild; /**< Active MDI child. */
BOOL m_bNoIcons; /**< TRUE if no icons are used. */
DWORD m_dwInitSignature; /**< Initialization state signature to synch up posted init requests.
*/
CImageList m_imageList; /**< Tab image list. */
CMDIFrameWnd* m_pMDIFrameWnd; /**< Pointer to the owner frame. */
CMDIChildList m_arMDIChildern; /**< Array of the MDI windows added to the tab control. */
CXTPMDIClientWnd* m_pMDIClientWnd; /**< Window that receives messages on behalf of the MDI
client. */
CIconWndMap m_mapTabIcons; /**< Hash table that maps icons to the MDI child frame windows. */
CStringMap m_mapTabLabels; /**< Hash table that maps labels to the MDI child frame windows. */
friend class CXTPMDIClientWnd;
};
//////////////////////////////////////////////////////////////////////
/** @cond */
AFX_INLINE void CXTPMDIWndTab::SetMenuID(UINT popupMenuID, int nPos, UINT nDefCmd)
{
m_popupMenuID = popupMenuID;
m_nPos = nPos;
m_nDefCmd = nDefCmd;
}
AFX_INLINE void CXTPMDIWndTab::SetBorderGap(int iBorderGap)
{
m_iBorderGap = iBorderGap;
m_pMDIClientWnd->SetBorderGap(iBorderGap + ::GetSystemMetrics(SM_CXSIZEFRAME));
}
/** @endcond */
# include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h"
/** @cond */
#endif // !defined(__XTPMDIWNDTAB_H__)
/** @endcond */