DockedTabControl.cpp 1.9 KB

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