/*------------------------------------------------------------------------------
 src/bin/djview/windowTool.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "window.h"
#include "widget.h"
#include "magnifyTool.h"
#include "colorSampleTool.h"
#include "imageInfoTool.h"
#include "imageOpTool.h"
#include "app.h"
#include <djButtonWidget.h>

namespace djview {

void Window::toolMagnifyCallback()
{
  if (! _callbacks) return;
  djviewApp->magnifyTool()->show();
  djviewApp->magnifyTool()->set(_viewWidget);
}

void Window::toolColorSampleCallback()
{
  if (! _callbacks) return;
  djviewApp->colorSampleTool()->show();
  djviewApp->colorSampleTool()->set(_viewWidget);
}

void Window::toolImageInfoCallback()
{
  if (! _callbacks) return;
  djviewApp->imageInfoTool()->show();
  djviewApp->imageInfoTool()->set(_fileName, _image);
}

void Window::toolImageOpCallback()
{
  if (! _callbacks) return;
  djviewApp->imageOpTool()->show();
}

void Window::toolUpdate()
{
  if (! _toolMode) return;
  
  DJ_DBG_FNC("Window::toolUpdate");
  
  _callbacks = false;
  
  djviewApp->magnifyTool()->set(_viewWidget);
  djviewApp->colorSampleTool()->set(_viewWidget);
  djviewApp->imageInfoTool()->set(_fileName, _image);
  
  _callbacks = true;
}

void Window::toolModeCallback(bool in)
{
  if (! _callbacks) return;
  _toolMode = in;
  toolModeUpdate();
}

void Window::toolModeCallback() { toolModeCallback(! _toolMode); }

void Window::toolModeUpdate()
{
  _callbacks = false;
  
  _viewWidget->toolMode(_toolMode);
  _toolModeButton->set(_toolMode);
  
  _callbacks = true;
}

}
