/*=========================================================================

  Module:    $RCSfile: vtkKWWidgetWithScrollbarsSubclass.cxx.in,v $

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "@WidgetType@WithScrollbars.h"
#include "vtkObjectFactory.h"
#include "vtkKWScrollbar.h"
#include "@WidgetType@.h"

#include <vtksys/stl/string>

//----------------------------------------------------------------------------
vtkStandardNewMacro(@WidgetType@WithScrollbars);
vtkCxxRevisionMacro(@WidgetType@WithScrollbars, "$Revision: 1.5 $");

//----------------------------------------------------------------------------
@WidgetType@WithScrollbars::@WidgetType@WithScrollbars()
{
  this->Widget = @WidgetType@::New();
}

//----------------------------------------------------------------------------
@WidgetType@WithScrollbars::~@WidgetType@WithScrollbars()
{
  if (this->Widget)
    {
    this->Widget->Delete();
    this->Widget = NULL;
    }
}

//----------------------------------------------------------------------------
@WidgetType@* @WidgetType@WithScrollbars::GetWidget()
{
  return this->Widget;
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::CreateWidget()
{
  // Check if already created

  if (this->IsCreated())
    {
    vtkErrorMacro(<< this->GetClassName() << " already created");
    return;
    }

  // Call the superclass to create the whole widget

  this->Superclass::CreateWidget();

  // Create the widget

  this->Widget->SetParent(this);
  this->Widget->Create();
  if (!this->Widget->IsCreated())
    {
    vtkErrorMacro(<< this->GetClassName() << " failed creating @WidgetType@");
    return;
    }

  // Now that we have been created, make sure we are associated to
  // the scrollbars created by the super, *if any*

  this->AssociateVerticalScrollbarToWidget(this->Widget);
  this->AssociateHorizontalScrollbarToWidget(this->Widget);

  // Pack

  this->Pack();

  // Update enable state

  this->UpdateEnableState();
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::CreateVerticalScrollbar()
{
  this->Superclass::CreateVerticalScrollbar();
  this->AssociateVerticalScrollbarToWidget(this->Widget);
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::CreateHorizontalScrollbar()
{
  this->Superclass::CreateHorizontalScrollbar();
  this->AssociateHorizontalScrollbarToWidget(this->Widget);
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::Pack()
{
  this->PackScrollbarsWithWidget(this->Widget);
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::UpdateEnableState()
{
  this->Superclass::UpdateEnableState();

  this->PropagateEnableState(this->Widget);
}

//----------------------------------------------------------------------------
void @WidgetType@WithScrollbars::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
  os << indent << "Widget: ";
  if (this->Widget)
    {
    os << this->Widget << endl;
    }
  else
    {
    os << "(None)" << endl;
    }
}
