void CXTPDockingPaneTabbedContainer::OnCaptionButtonClick(CXTPDockingPaneCaptionButton* pButton)
{
	CXTPDockingPane* pSelectedPane = m_pSelectedPane;

	CXTPDockingPaneManager* pManager = GetDockingPaneManager();

	switch (pButton->GetID())
	{
	case XTP_IDS_DOCKINGPANE_CLOSE:

		if (pManager->m_bCloseGroupOnButtonClick)
		{
			POSITION pos = m_lstPanes.GetTailPosition();
			while (pos)
			{
				CXTPDockingPane* pPane = (CXTPDockingPane*)m_lstPanes.GetPrev(pos);

				ClosePane(pPane);
			}

		}
		else if (pSelectedPane)
		{
			ClosePane(pSelectedPane);
		}
		break;


	case XTP_IDS_DOCKINGPANE_AUTOHIDE:

		if (!IsHidden())
		{
			if (!pManager->NotifyAction(xtpPaneActionUnpinning, pSelectedPane))
			{
				GetDockingSite()->SetFocus();
				NormalizeDockingSize();
				pSelectedPane->Hide();
				pManager->NotifyAction(xtpPaneActionUnpinned, pSelectedPane);
			}

		}
		else
		{
			GetDockingPaneManager()->ToggleDocking(pManager->m_bHideGroupOnButtonClick ?
				(CXTPDockingPaneBase*)this : (CXTPDockingPaneBase*)pSelectedPane);
		}

		break;

	case XTP_IDS_DOCKINGPANE_MAXIMIZE:
		Maximize();
		break;

	case XTP_IDS_DOCKINGPANE_RESTORE:
		Restore();
		break;

	}
}
void CXTPDockingPaneTabbedContainer::ClosePane(CXTPDockingPane* pPane)
{
	if (!pPane)
		return;

	if ((pPane->GetOptions() & xtpPaneNoCloseable) != 0)
		return;

	CXTPDockingPaneManager* pManager = GetDockingPaneManager();

	pPane->InternalAddRef();
	if (!pManager->NotifyAction(xtpPaneActionClosing, pPane))
	{
		pPane->Close();
		pManager->NotifyAction(xtpPaneActionClosed, pPane);
	}
	pPane->InternalRelease();
}
void CXTPDockingPaneSidePanel::OnCaptionButtonClick(CXTPDockingPaneCaptionButton* pButton)
{
	CXTPDockingPaneManager* pManager = GetDockingPaneManager();

	switch (pButton->GetID())
	{
		case XTP_IDS_DOCKINGPANE_CLOSE:
			{
				CXTPDockingPaneBaseList lstPanes;
				FindPane(xtpPaneTypeDockingPane, &lstPanes);

				POSITION pos = lstPanes.GetTailPosition();
				while (pos)
				{
					CXTPDockingPane* pPane = (CXTPDockingPane*)lstPanes.GetPrev(pos);

					if ((pPane->GetOptions() & xtpPaneNoCloseable) != 0)
						continue;

					pPane->InternalAddRef();

					if (!pManager->NotifyAction(xtpPaneActionClosing, pPane))
					{
						pPane->Close();
						pManager->NotifyAction(xtpPaneActionClosed, pPane);
					}

					pPane->InternalRelease();
				}
			}
			break;

		case XTP_IDS_DOCKINGPANE_AUTOHIDE:
			OnPinButtonClick();
			break;
	}
}