1 /*
2 	GWEN
3 	Copyright (c) 2010 Facepunch Studios
4 	See license in Gwen.h
5 */
6 
7 #include "Gwen/Gwen.h"
8 #include "Gwen/Skin.h"
9 #include "Gwen/Controls/DockedTabControl.h"
10 #include "Gwen/Controls/Highlight.h"
11 #include "Gwen/DragAndDrop.h"
12 #include "Gwen/Controls/WindowControl.h"
13 
14 using namespace Gwen;
15 using namespace Gwen::Controls;
16 
GWEN_CONTROL_CONSTRUCTOR(DockedTabControl)17 GWEN_CONTROL_CONSTRUCTOR(DockedTabControl)
18 {
19 	m_WindowControl = NULL;
20 
21 	Dock(Pos::Fill);
22 
23 	m_pTitleBar = new TabTitleBar(this);
24 	m_pTitleBar->Dock(Pos::Top);
25 	m_pTitleBar->SetHidden(true);
26 }
27 
Layout(Skin::Base * skin)28 void DockedTabControl::Layout(Skin::Base* skin)
29 {
30 	GetTabStrip()->SetHidden(TabCount() <= 1);
31 	UpdateTitleBar();
32 	BaseClass::Layout(skin);
33 }
34 
UpdateTitleBar()35 void DockedTabControl::UpdateTitleBar()
36 {
37 	if (!GetCurrentButton()) return;
38 
39 	m_pTitleBar->UpdateFromTab(GetCurrentButton());
40 }
41 
DragAndDrop_StartDragging(Gwen::DragAndDrop::Package * pPackage,int x,int y)42 void DockedTabControl::DragAndDrop_StartDragging(Gwen::DragAndDrop::Package* pPackage, int x, int y)
43 {
44 	BaseClass::DragAndDrop_StartDragging(pPackage, x, y);
45 
46 	SetHidden(true);
47 	// This hiding our parent thing is kind of lousy.
48 	GetParent()->SetHidden(true);
49 }
50 
DragAndDrop_EndDragging(bool bSuccess,int,int)51 void DockedTabControl::DragAndDrop_EndDragging(bool bSuccess, int /*x*/, int /*y*/)
52 {
53 	SetHidden(false);
54 
55 	if (!bSuccess)
56 	{
57 		GetParent()->SetHidden(false);
58 	}
59 
60 	/*
61 	if ( !bSuccess )
62 	{
63 		// Create our window control
64 		if ( !m_WindowControl )
65 		{
66 			m_WindowControl = new WindowControl( GetCanvas() );
67 			m_WindowControl->SetBounds( x, y, Width(), Height() );
68 		}
69 
70 		m_WindowControl->SetPosition( x, y );
71 		SetParent( m_WindowControl );
72 		SetPosition( 0, 0 );
73 		Dock( Pos::Fill );
74 	}
75 	*/
76 }
77 
MoveTabsTo(DockedTabControl * pTarget)78 void DockedTabControl::MoveTabsTo(DockedTabControl* pTarget)
79 {
80 	Base::List Children = GetTabStrip()->Children;
81 	for (Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter)
82 	{
83 		TabButton* pButton = (*iter)->DynamicCastTabButton();
84 		if (!pButton) continue;
85 
86 		pTarget->AddPage(pButton);
87 	}
88 
89 	Invalidate();
90 }