<commit_before>// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2; -*-

/*
  Copyright (C) 2009, Anders Ronnbrant - andro@lysator.liu.se
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  You should have received a copy of the FreeBSD license, if not see:
  <http://www.freebsd.org/copyright/freebsd-license.html>.
*/

#include "vincenty.h"

#include <iomanip>

namespace vincenty
{
// Geographical position
// ------------------------------------------------------------------------

//! Constructor, defaults latitude and longitude to zero (0).
vposition::vposition()
    : coords()
{
  coords.a[0] = 0;
  coords.a[1] = 0;
}

//! Constructor taking two doubles for initialization.
vposition::vposition( double _lat, double _lon )
    : coords()
{
  coords.a[0] = _lat;
  coords.a[1] = _lon;
}

//! Integer degrees from float radian.
int vposition::deg( const double rad )
{
  return int( to_deg(rad) );
}

//! Extracts integer minutes from float radian.
int vposition::min( const double rad )
{
  return int( ( degf(rad) - deg(rad) ) * 60 );
}

//! Extracts integer seconds from float radian.
int vposition::sec( const double rad )
{
  return int( ( minf(rad) - min(rad) ) * 60 );
}

//! Converts radians to degrees.
double vposition::degf( const double rad )
{
  return to_deg(rad);
}

//! Extracts decimal part minutes from float radian.
double vposition::minf( const double rad )
{
  return ( degf(rad) - deg(rad) ) * 60;
}

//! Extracts decimal part seconds from float radian.
double vposition::secf( const double rad )
{
  return ( minf(rad) - min(rad) ) * 60;
}

// Operators for vposition.
bool operator==( const vposition& lhs, const vposition& rhs )
{
  if ( ulpcmp(lhs.coords.a[0], rhs.coords.a[0]) &&
       ulpcmp(lhs.coords.a[1], rhs.coords.a[1]) ) {
    return true;
  } else {
    return false;
  }
}

vposition vposition::operator+( const vdirection& rhs ) const
{
  return direct((*this),rhs);
}

vposition vposition::operator-( const vdirection& rhs ) const
{
  return direct((*this),rhs.bearing2,rhs.distance);
}

vdirection vposition::operator-( const vposition& rhs ) const
{
  return inverse(rhs,(*this));
}

vposition vposition::operator^( const vposition& rhs ) const
{
  vdirection d = (*this) - rhs;
  return direct((*this),d.bearing1,d.distance/2.0);
}

// Geographical direction
// ------------------------------------------------------------------------

//! Constructor, defaults bearings and distance to 0 (zero).
vdirection::vdirection()
    : bearing1(0), distance(0), bearing2(0)
{
}

/*!
 * Constructor taking three doubles for initialization.
 *
 * !!OBS!! This constructor allows for invalid settings. I.e. the two bearings
 * combined with the distance might not always be a possible solution for any
 * two points on the geoid.
 *
 * @param _bearing1 The bearing for the direction.
 * @param _distance The distance to travel in the current bearing.
 * @param _bearing2 The reversed bearing for the direction.
 */
vdirection::vdirection( double _bearing1, double _distance, double _bearing2 )
    : bearing1(_bearing1), distance(_distance), bearing2(_bearing2)
{
}

// Operators for vdirection.
bool operator==( const vdirection& lhs, const vdirection& rhs )
{
  if ( ulpcmp(lhs.bearing1, rhs.bearing1) &&
       ulpcmp(lhs.distance, rhs.distance) ) {
    return true;
  } else {
    return false;
  }
}

vdirection vdirection::operator/( const double rhs ) const
{
  return vdirection((*this).bearing1,(*this).distance/rhs);
}

vdirection vdirection::operator*( const double rhs ) const
{
  return vdirection((*this).bearing1,(*this).distance*rhs);
}

} // namespace end
<commit_msg> Wrong bearing used for middle point operator.<commit_after>// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2; -*-

/*
  Copyright (C) 2009, Anders Ronnbrant - andro@lysator.liu.se
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  You should have received a copy of the FreeBSD license, if not see:
  <http://www.freebsd.org/copyright/freebsd-license.html>.
*/

#include "vincenty.h"

#include <iomanip>

namespace vincenty
{
// Geographical position
// ------------------------------------------------------------------------

//! Constructor, defaults latitude and longitude to zero (0).
vposition::vposition()
    : coords()
{
  coords.a[0] = 0;
  coords.a[1] = 0;
}

//! Constructor taking two doubles for initialization.
vposition::vposition( double _lat, double _lon )
    : coords()
{
  coords.a[0] = _lat;
  coords.a[1] = _lon;
}

//! Integer degrees from float radian.
int vposition::deg( const double rad )
{
  return int( to_deg(rad) );
}

//! Extracts integer minutes from float radian.
int vposition::min( const double rad )
{
  return int( ( degf(rad) - deg(rad) ) * 60 );
}

//! Extracts integer seconds from float radian.
int vposition::sec( const double rad )
{
  return int( ( minf(rad) - min(rad) ) * 60 );
}

//! Converts radians to degrees.
double vposition::degf( const double rad )
{
  return to_deg(rad);
}

//! Extracts decimal part minutes from float radian.
double vposition::minf( const double rad )
{
  return ( degf(rad) - deg(rad) ) * 60;
}

//! Extracts decimal part seconds from float radian.
double vposition::secf( const double rad )
{
  return ( minf(rad) - min(rad) ) * 60;
}

// Operators for vposition.
bool operator==( const vposition& lhs, const vposition& rhs )
{
  if ( ulpcmp(lhs.coords.a[0], rhs.coords.a[0]) &&
       ulpcmp(lhs.coords.a[1], rhs.coords.a[1]) ) {
    return true;
  } else {
    return false;
  }
}

vposition vposition::operator+( const vdirection& rhs ) const
{
  return direct((*this),rhs);
}

vposition vposition::operator-( const vdirection& rhs ) const
{
  return direct((*this),rhs.bearing2,rhs.distance);
}

vdirection vposition::operator-( const vposition& rhs ) const
{
  return inverse(rhs,(*this));
}

vposition vposition::operator^( const vposition& rhs ) const
{
  vdirection d = inverse(rhs,(*this));
  return direct((*this),d.bearing2,d.distance/2.0);
}

// Geographical direction
// ------------------------------------------------------------------------

//! Constructor, defaults bearings and distance to 0 (zero).
vdirection::vdirection()
    : bearing1(0), distance(0), bearing2(0)
{
}

/*!
 * Constructor taking three doubles for initialization.
 *
 * !!OBS!! This constructor allows for invalid settings. I.e. the two bearings
 * combined with the distance might not always be a possible solution for any
 * two points on the geoid.
 *
 * @param _bearing1 The bearing for the direction.
 * @param _distance The distance to travel in the current bearing.
 * @param _bearing2 The reversed bearing for the direction.
 */
vdirection::vdirection( double _bearing1, double _distance, double _bearing2 )
    : bearing1(_bearing1), distance(_distance), bearing2(_bearing2)
{
}

// Operators for vdirection.
bool operator==( const vdirection& lhs, const vdirection& rhs )
{
  if ( ulpcmp(lhs.bearing1, rhs.bearing1) &&
       ulpcmp(lhs.distance, rhs.distance) ) {
    return true;
  } else {
    return false;
  }
}

vdirection vdirection::operator/( const double rhs ) const
{
  return vdirection((*this).bearing1,(*this).distance/rhs);
}

vdirection vdirection::operator*( const double rhs ) const
{
  return vdirection((*this).bearing1,(*this).distance*rhs);
}

} // namespace end
<|endoftext|>


<commit_before>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html 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 notices for more information.

=========================================================================*/
// Qmitk related includes
#include "QmitkPropertyListViewItem.h"
#include "QmitkPropertyListViewItemFactory.h"
#include "QmitkMaterialEditor.h"

// mitk related includes
#include "mitkConfig.h"
#include "mitkRenderWindow.h"
#include "mitkPropertyList.h"
#include "mitkProperties.h"
#include "mitkColorProperty.h"
#include "mitkPropertyManager.h"
#include "mitkRenderingManager.h"
#include "mitkEnumerationProperty.h"
#include "mitkMaterialProperty.h"

// QT related includes
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qcolordialog.h>
#include <qvalidator.h>
#include <qhbox.h>
#include <qslider.h>
#include <qcombobox.h>

#include "enabled.xpm"
#include "disabled.xpm"

QmitkPropertyListViewItem::QmitkPropertyListViewItem(std::string name, mitk::PropertyList* propertyList, QWidget* parent, bool createOnlyControl)
  : m_Name(name), m_PropertyList(propertyList), m_Label(NULL), m_Control(NULL)
{
  if (!createOnlyControl)
  {
    CreateEnabledButton(parent);
    m_Label = new QLabel(name.c_str(),parent);
    m_Label->show();
  }
};

void QmitkPropertyListViewItem::CreateEnabledButton(QWidget* parent)
{
  m_EnabledButton = new QPushButton(parent);
  connect(
    (QObject*)(m_EnabledButton),
    SIGNAL(clicked()),
    (QObject*)(this),
    SLOT(EnabledButtonClicked())
  );
  m_EnabledButton->show();
  UpdateEnabledView();
}

QmitkPropertyListViewItem* QmitkPropertyListViewItem::CreateInstance(mitk::PropertyList *propList, const std::string name, QWidget* parent, bool createOnlyControl)
{
  return QmitkPropertyListViewItemFactory::GetInstance()->CreateQmitkPropertyListViewItem(propList,name,parent,createOnlyControl);
}

void QmitkPropertyListViewItem::CheckBoxControlActivated(bool on)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::BoolProperty(on));
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::StringControlActivated(const QString &text)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::StringProperty(text.ascii()));
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::FloatControlActivated(const QString &text)
{
  if (((QLineEdit*)m_Control)->hasAcceptableInput())
  {
    m_Control->setPaletteForegroundColor(Qt::black);
    float value = text.toFloat();
    mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
    if (value != floatProp->GetValue())
    {
      m_PropertyList->SetProperty(m_Name.c_str(), new mitk::FloatProperty(value));
    }
  }
  else
  {
    m_Control->setPaletteForegroundColor(Qt::red);
  }
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::IntControlActivated(const QString &text)
{
  if (((QLineEdit*)m_Control)->hasAcceptableInput())
  {
    m_Control->setPaletteForegroundColor(Qt::black);
    int value = text.toInt();
    mitk::IntProperty* intProp = dynamic_cast<mitk::IntProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
    if (value != intProp->GetValue())
    {
      m_PropertyList->SetProperty(m_Name.c_str(), new mitk::IntProperty(value));
    }
  }
  else
  {
    m_Control->setPaletteForegroundColor(Qt::red);
  }
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::ColorControlActivated()
{
  mitk::ColorProperty* colorProp = dynamic_cast<mitk::ColorProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  mitk::Color col = colorProp->GetColor();
  QColor result = QColorDialog::getColor(QColor((int)(col.GetRed() * 255), (int)(col.GetGreen() * 255), (int)(col.GetBlue() * 255)));
  if (result.isValid())
  {
    col.SetRed(result.red() / 255.0);
    col.SetGreen(result.green() / 255.0);
    col.SetBlue(result.blue() / 255.0);
    colorProp->SetColor(col);
    m_PropertyList->InvokeEvent(itk::ModifiedEvent());
    m_Control->setPaletteBackgroundColor(result);
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
}

void QmitkPropertyListViewItem::UpdateView()
{
  m_Control->blockSignals(true);
  mitk::BaseProperty* baseProp = m_PropertyList->GetProperty(m_Name.c_str());
  if (mitk::BoolProperty* boolProp = dynamic_cast<mitk::BoolProperty*>(baseProp))
  {
     if (QCheckBox* cb = dynamic_cast<QCheckBox*>(m_Control)) {
      cb ->setChecked(boolProp->GetValue());
     } else {
       std::cout << "warning: non-checkbox control for bool property " << m_Name << std::endl;
     }
  }
  else if (mitk::StringProperty* stringProp = dynamic_cast<mitk::StringProperty*>(baseProp))
  {
    if (QLineEdit* qle = dynamic_cast<QLineEdit*>(m_Control)) {
    qle->setText(QString(stringProp->GetValue()));
} else {
       std::cout << "warning: non-lineedit control for string property " << m_Name << std::endl;
}

  }
  else if (mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(baseProp))
  {
    QString text;
    text.setNum(floatProp->GetValue());
    ((QLineEdit*)(m_Control))->setText(text);
  }

  else if (mitk::ColorProperty* colorProp = dynamic_cast<mitk::ColorProperty*>(baseProp))
  {
    mitk::Color col = colorProp->GetColor();
    QColor qcol((int)(col.GetRed() * 255), (int)(col.GetGreen() * 255),(int)( col.GetBlue() * 255));
    ((QPushButton*)(m_Control))->setPaletteBackgroundColor(qcol);
  }

  else if (mitk::EnumerationProperty* enumerationProp = dynamic_cast<mitk::EnumerationProperty*>(baseProp))
  {
    QComboBox* combo = ( ( QComboBox* ) m_Control );
    std::string enumerationValue = enumerationProp->GetValueAsString();
    for ( int item = 0 ; item < combo->count() ; ++item )
    {
      if ( enumerationValue == combo->text( item ).latin1() )
      {
         combo->setCurrentItem( item );
         break;
      }
    }
  }
  m_Control->blockSignals(false);
}

void QmitkPropertyListViewItem::UpdateEnabledView()
{
  static const QPixmap enabledPix((const char **)enabled_xpm);
  static const QPixmap disabledPix((const char **)disabled_xpm);
  if (m_PropertyList->IsEnabled(m_Name.c_str())) /* baseProp->GetEnabled()) */
  {
    m_EnabledButton->setPixmap(enabledPix);
    if (m_Control) {m_Control->setEnabled(true);}
    if (m_Label) {m_Label->setEnabled(true);}
  }
  else
  {
    m_EnabledButton->setPixmap(disabledPix);
    if (m_Control) {m_Control->setEnabled(false);}
    if (m_Label) {m_Label->setEnabled(false);}
  }
}

void QmitkPropertyListViewItem::EnabledButtonClicked()
{
  //baseProp->SetEnabled(! baseProp->GetEnabled());
  m_PropertyList->SetEnabled(m_Name.c_str(), ! m_PropertyList->IsEnabled(m_Name.c_str()));
  UpdateEnabledView();
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::ComboBoxItemActivated(const QString &item)
{
  mitk::EnumerationProperty* enumProp = dynamic_cast<mitk::EnumerationProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  if ( enumProp != NULL )
  {
    std::string activatedItem( item.latin1() );
    if ( activatedItem != enumProp->GetValueAsString() )
    {
      if ( enumProp->IsValidEnumerationValue( activatedItem ) )
      {
         enumProp->SetValue( activatedItem );
         m_PropertyList->InvokeEvent( itk::ModifiedEvent() );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
      }
    }
  }
}

void  QmitkPropertyListViewFloatSlider::SliderValueChanged(int value)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::FloatProperty(value / 100.0f));
  UpdateView();
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewFloatSlider::UpdateView()
{
  m_Slider->blockSignals(true);
  mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  if (floatProp)
  {
    QString text;
    text.setNum(floatProp->GetValue(),'f',2);
    m_ValueLabel->setText(text);
    m_Slider->setValue((int)(floatProp->GetValue() * 100));
  }
  m_Slider->blockSignals(false);
}

void QmitkPropertyListViewItem::MaterialEditorActivated()
{
  if ( mitk::MaterialProperty* materialProperty = dynamic_cast<mitk::MaterialProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer()))
  {
    QmitkMaterialEditor* materialEditor = new QmitkMaterialEditor( NULL );
    materialEditor->Initialize( materialProperty );
    if ( materialEditor->exec() == QDialog::Accepted )
    {
      m_PropertyList->InvokeEvent(itk::ModifiedEvent());
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();
    }
    delete materialEditor;
  }
}

<commit_msg>comment warnings<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html 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 notices for more information.

=========================================================================*/
// Qmitk related includes
#include "QmitkPropertyListViewItem.h"
#include "QmitkPropertyListViewItemFactory.h"
#include "QmitkMaterialEditor.h"

// mitk related includes
#include "mitkConfig.h"
#include "mitkRenderWindow.h"
#include "mitkPropertyList.h"
#include "mitkProperties.h"
#include "mitkColorProperty.h"
#include "mitkPropertyManager.h"
#include "mitkRenderingManager.h"
#include "mitkEnumerationProperty.h"
#include "mitkMaterialProperty.h"

// QT related includes
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qcolordialog.h>
#include <qvalidator.h>
#include <qhbox.h>
#include <qslider.h>
#include <qcombobox.h>

#include "enabled.xpm"
#include "disabled.xpm"

QmitkPropertyListViewItem::QmitkPropertyListViewItem(std::string name, mitk::PropertyList* propertyList, QWidget* parent, bool createOnlyControl)
  : m_Name(name), m_PropertyList(propertyList), m_Label(NULL), m_Control(NULL)
{
  if (!createOnlyControl)
  {
    CreateEnabledButton(parent);
    m_Label = new QLabel(name.c_str(),parent);
    m_Label->show();
  }
};

void QmitkPropertyListViewItem::CreateEnabledButton(QWidget* parent)
{
  m_EnabledButton = new QPushButton(parent);
  connect(
    (QObject*)(m_EnabledButton),
    SIGNAL(clicked()),
    (QObject*)(this),
    SLOT(EnabledButtonClicked())
  );
  m_EnabledButton->show();
  UpdateEnabledView();
}

QmitkPropertyListViewItem* QmitkPropertyListViewItem::CreateInstance(mitk::PropertyList *propList, const std::string name, QWidget* parent, bool createOnlyControl)
{
  return QmitkPropertyListViewItemFactory::GetInstance()->CreateQmitkPropertyListViewItem(propList,name,parent,createOnlyControl);
}

void QmitkPropertyListViewItem::CheckBoxControlActivated(bool on)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::BoolProperty(on));
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::StringControlActivated(const QString &text)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::StringProperty(text.ascii()));
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::FloatControlActivated(const QString &text)
{
  if (((QLineEdit*)m_Control)->hasAcceptableInput())
  {
    m_Control->setPaletteForegroundColor(Qt::black);
    float value = text.toFloat();
    mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
    if (value != floatProp->GetValue())
    {
      m_PropertyList->SetProperty(m_Name.c_str(), new mitk::FloatProperty(value));
    }
  }
  else
  {
    m_Control->setPaletteForegroundColor(Qt::red);
  }
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::IntControlActivated(const QString &text)
{
  if (((QLineEdit*)m_Control)->hasAcceptableInput())
  {
    m_Control->setPaletteForegroundColor(Qt::black);
    int value = text.toInt();
    mitk::IntProperty* intProp = dynamic_cast<mitk::IntProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
    if (value != intProp->GetValue())
    {
      m_PropertyList->SetProperty(m_Name.c_str(), new mitk::IntProperty(value));
    }
  }
  else
  {
    m_Control->setPaletteForegroundColor(Qt::red);
  }
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::ColorControlActivated()
{
  mitk::ColorProperty* colorProp = dynamic_cast<mitk::ColorProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  mitk::Color col = colorProp->GetColor();
  QColor result = QColorDialog::getColor(QColor((int)(col.GetRed() * 255), (int)(col.GetGreen() * 255), (int)(col.GetBlue() * 255)));
  if (result.isValid())
  {
    col.SetRed(result.red() / 255.0);
    col.SetGreen(result.green() / 255.0);
    col.SetBlue(result.blue() / 255.0);
    colorProp->SetColor(col);
    m_PropertyList->InvokeEvent(itk::ModifiedEvent());
    m_Control->setPaletteBackgroundColor(result);
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
}

void QmitkPropertyListViewItem::UpdateView()
{
  m_Control->blockSignals(true);
  mitk::BaseProperty* baseProp = m_PropertyList->GetProperty(m_Name.c_str());
  if (mitk::BoolProperty* boolProp = dynamic_cast<mitk::BoolProperty*>(baseProp))
  {
     if (QCheckBox* cb = dynamic_cast<QCheckBox*>(m_Control)) {
      cb ->setChecked(boolProp->GetValue());
     } else {
       //std::cout << "warning: non-checkbox control for bool property " << m_Name << std::endl;
     }
  }
  else if (mitk::StringProperty* stringProp = dynamic_cast<mitk::StringProperty*>(baseProp))
  {
    if (QLineEdit* qle = dynamic_cast<QLineEdit*>(m_Control)) {
    qle->setText(QString(stringProp->GetValue()));
} else {
       //std::cout << "warning: non-lineedit control for string property " << m_Name << std::endl;
}

  }
  else if (mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(baseProp))
  {
    QString text;
    text.setNum(floatProp->GetValue());
    ((QLineEdit*)(m_Control))->setText(text);
  }

  else if (mitk::ColorProperty* colorProp = dynamic_cast<mitk::ColorProperty*>(baseProp))
  {
    mitk::Color col = colorProp->GetColor();
    QColor qcol((int)(col.GetRed() * 255), (int)(col.GetGreen() * 255),(int)( col.GetBlue() * 255));
    ((QPushButton*)(m_Control))->setPaletteBackgroundColor(qcol);
  }

  else if (mitk::EnumerationProperty* enumerationProp = dynamic_cast<mitk::EnumerationProperty*>(baseProp))
  {
    QComboBox* combo = ( ( QComboBox* ) m_Control );
    std::string enumerationValue = enumerationProp->GetValueAsString();
    for ( int item = 0 ; item < combo->count() ; ++item )
    {
      if ( enumerationValue == combo->text( item ).latin1() )
      {
         combo->setCurrentItem( item );
         break;
      }
    }
  }
  m_Control->blockSignals(false);
}

void QmitkPropertyListViewItem::UpdateEnabledView()
{
  static const QPixmap enabledPix((const char **)enabled_xpm);
  static const QPixmap disabledPix((const char **)disabled_xpm);
  if (m_PropertyList->IsEnabled(m_Name.c_str())) /* baseProp->GetEnabled()) */
  {
    m_EnabledButton->setPixmap(enabledPix);
    if (m_Control) {m_Control->setEnabled(true);}
    if (m_Label) {m_Label->setEnabled(true);}
  }
  else
  {
    m_EnabledButton->setPixmap(disabledPix);
    if (m_Control) {m_Control->setEnabled(false);}
    if (m_Label) {m_Label->setEnabled(false);}
  }
}

void QmitkPropertyListViewItem::EnabledButtonClicked()
{
  //baseProp->SetEnabled(! baseProp->GetEnabled());
  m_PropertyList->SetEnabled(m_Name.c_str(), ! m_PropertyList->IsEnabled(m_Name.c_str()));
  UpdateEnabledView();
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewItem::ComboBoxItemActivated(const QString &item)
{
  mitk::EnumerationProperty* enumProp = dynamic_cast<mitk::EnumerationProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  if ( enumProp != NULL )
  {
    std::string activatedItem( item.latin1() );
    if ( activatedItem != enumProp->GetValueAsString() )
    {
      if ( enumProp->IsValidEnumerationValue( activatedItem ) )
      {
         enumProp->SetValue( activatedItem );
         m_PropertyList->InvokeEvent( itk::ModifiedEvent() );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
      }
    }
  }
}

void  QmitkPropertyListViewFloatSlider::SliderValueChanged(int value)
{
  m_PropertyList->SetProperty(m_Name.c_str(), new mitk::FloatProperty(value / 100.0f));
  UpdateView();
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}

void QmitkPropertyListViewFloatSlider::UpdateView()
{
  m_Slider->blockSignals(true);
  mitk::FloatProperty* floatProp = dynamic_cast<mitk::FloatProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer());
  if (floatProp)
  {
    QString text;
    text.setNum(floatProp->GetValue(),'f',2);
    m_ValueLabel->setText(text);
    m_Slider->setValue((int)(floatProp->GetValue() * 100));
  }
  m_Slider->blockSignals(false);
}

void QmitkPropertyListViewItem::MaterialEditorActivated()
{
  if ( mitk::MaterialProperty* materialProperty = dynamic_cast<mitk::MaterialProperty*>(m_PropertyList->GetProperty(m_Name.c_str()).GetPointer()))
  {
    QmitkMaterialEditor* materialEditor = new QmitkMaterialEditor( NULL );
    materialEditor->Initialize( materialProperty );
    if ( materialEditor->exec() == QDialog::Accepted )
    {
      m_PropertyList->InvokeEvent(itk::ModifiedEvent());
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();
    }
    delete materialEditor;
  }
}

<|endoftext|>


<commit_before>#include "pch.h"
#include "Servo.h"

namespace winrt::servo {

void on_load_started() { sServo->Delegate().OnServoLoadStarted(); }

void on_load_ended() { sServo->Delegate().OnServoLoadEnded(); }

void on_history_changed(bool back, bool forward) {
  sServo->Delegate().OnServoHistoryChanged(back, forward);
}

void on_shutdown_complete() { sServo->Delegate().OnServoShutdownComplete(); }

void on_title_changed(const char *title) {
  sServo->Delegate().OnServoTitleChanged(char2hstring(title));
}

void on_url_changed(const char *url) {
  sServo->Delegate().OnServoURLChanged(char2hstring(url));
}

void flush() { sServo->Delegate().Flush(); }

void make_current() { sServo->Delegate().MakeCurrent(); }

void wakeup() { sServo->Delegate().WakeUp(); }

bool on_allow_navigation(const char *url) {
  return sServo->Delegate().OnServoAllowNavigation(char2hstring(url));
};

void on_animating_changed(bool aAnimating) {
  sServo->Delegate().OnServoAnimatingChanged(aAnimating);
}

void on_panic(const char *backtrace) {
  throw hresult_error(E_FAIL, char2hstring(backtrace));
}

void on_ime_state_changed(bool aShow) {
  sServo->Delegate().OnServoIMEStateChanged(aShow);
}

void set_clipboard_contents(const char *content) {
  // FIXME
}

const char *get_clipboard_contents() {
  // FIXME
  return nullptr;
}

void on_media_session_metadata(const char *title, const char *album,
                               const char *artist) {
  return sServo->Delegate().OnServoMediaSessionMetadata(
      char2hstring(title), char2hstring(album), char2hstring(artist));
}

void on_media_session_playback_state_change(
    const capi::CMediaSessionPlaybackState state) {
  return sServo->Delegate().OnServoMediaSessionPlaybackStateChange(state);
}

void prompt_alert(const char *message, bool trusted) {
  sServo->Delegate().OnServoPromptAlert(char2hstring(message), trusted);
}

Servo::PromptResult prompt_ok_cancel(const char *message, bool trusted) {
  return sServo->Delegate().OnServoPromptOkCancel(char2hstring(message),
                                                  trusted);
}

Servo::PromptResult prompt_yes_no(const char *message, bool trusted) {
  return sServo->Delegate().OnServoPromptYesNo(char2hstring(message), trusted);
}

const char *prompt_input(const char *message, const char *default,
                         bool trusted) {
  auto input = sServo->Delegate().OnServoPromptInput(
      char2hstring(message), char2hstring(default), trusted);
  if (input.has_value()) {
    return *hstring2char(*input);
  } else {
    return nullptr;
  }
}

Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
             float dpi, ServoDelegate &aDelegate)
    : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {

  capi::CInitOptions o;
  hstring defaultPrefs = L" --pref dom.webxr.enabled  --devtools=6000";
  o.args = *hstring2char(args + defaultPrefs);
  o.url = *hstring2char(url);
  o.width = mWindowWidth;
  o.height = mWindowHeight;
  o.density = dpi;
  o.enable_subpixel_text_antialiasing = false;
  o.vr_pointer = NULL;

  // 7 filter modules.
  /* Sample list of servo modules to filter.
  static char *pfilters[] = {
          "servo",
          "simpleservo",
          "simpleservo::jniapi",
          "simpleservo::gl_glue::egl",
          // Show JS errors by default.
          "script::dom::bindings::error",
          // Show GL errors by default.
          "canvas::webgl_thread",
          "compositing::compositor",
          "constellation::constellation",
  };
  */

  // Example Call when *pfilters[] is used:
  // o.vslogger_mod_list = pfilters; // servo log modules
  // o.vslogger_mod_size = sizeof(pfilters) / sizeof(pfilters[0]); //
  // Important: Number of modules in pfilters
  o.vslogger_mod_list = NULL;
  o.vslogger_mod_size = 0;

  sServo = this; // FIXME;

  capi::CHostCallbacks c;
  c.flush = &flush;
  c.make_current = &make_current;
  c.on_load_started = &on_load_started;
  c.on_load_ended = &on_load_ended;
  c.on_title_changed = &on_title_changed;
  c.on_url_changed = &on_url_changed;
  c.on_history_changed = &on_history_changed;
  c.on_animating_changed = &on_animating_changed;
  c.on_shutdown_complete = &on_shutdown_complete;
  c.on_allow_navigation = &on_allow_navigation;
  c.on_ime_state_changed = &on_ime_state_changed;
  c.get_clipboard_contents = &get_clipboard_contents;
  c.set_clipboard_contents = &set_clipboard_contents;
  c.on_media_session_metadata = &on_media_session_metadata;
  c.on_media_session_playback_state_change =
      &on_media_session_playback_state_change;
  c.prompt_alert = &prompt_alert;
  c.prompt_ok_cancel = &prompt_ok_cancel;
  c.prompt_yes_no = &prompt_yes_no;
  c.prompt_input = &prompt_input;

  capi::register_panic_handler(&on_panic);

  capi::init_with_egl(o, &wakeup, c);
}

Servo::~Servo() { sServo = nullptr; }

winrt::hstring char2hstring(const char *c_str) {
  // FIXME: any better way of doing this?
  auto str = std::string(c_str);
  int size_needed =
      MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
  std::wstring str2(size_needed, 0);
  MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &str2[0],
                      size_needed);
  winrt::hstring str3{str2};
  return str3;
}

std::unique_ptr<char *> hstring2char(hstring hstr) {
  const wchar_t *wc = hstr.c_str();
  size_t size = hstr.size() + 1;
  char *str = new char[size];
  size_t converted = 0;
  wcstombs_s(&converted, str, size, wc, hstr.size());
  return std::make_unique<char *>(str);
}

} // namespace winrt::servo
<commit_msg>Disable devtools for HoloLens.<commit_after>#include "pch.h"
#include "Servo.h"

namespace winrt::servo {

void on_load_started() { sServo->Delegate().OnServoLoadStarted(); }

void on_load_ended() { sServo->Delegate().OnServoLoadEnded(); }

void on_history_changed(bool back, bool forward) {
  sServo->Delegate().OnServoHistoryChanged(back, forward);
}

void on_shutdown_complete() { sServo->Delegate().OnServoShutdownComplete(); }

void on_title_changed(const char *title) {
  sServo->Delegate().OnServoTitleChanged(char2hstring(title));
}

void on_url_changed(const char *url) {
  sServo->Delegate().OnServoURLChanged(char2hstring(url));
}

void flush() { sServo->Delegate().Flush(); }

void make_current() { sServo->Delegate().MakeCurrent(); }

void wakeup() { sServo->Delegate().WakeUp(); }

bool on_allow_navigation(const char *url) {
  return sServo->Delegate().OnServoAllowNavigation(char2hstring(url));
};

void on_animating_changed(bool aAnimating) {
  sServo->Delegate().OnServoAnimatingChanged(aAnimating);
}

void on_panic(const char *backtrace) {
  throw hresult_error(E_FAIL, char2hstring(backtrace));
}

void on_ime_state_changed(bool aShow) {
  sServo->Delegate().OnServoIMEStateChanged(aShow);
}

void set_clipboard_contents(const char *content) {
  // FIXME
}

const char *get_clipboard_contents() {
  // FIXME
  return nullptr;
}

void on_media_session_metadata(const char *title, const char *album,
                               const char *artist) {
  return sServo->Delegate().OnServoMediaSessionMetadata(
      char2hstring(title), char2hstring(album), char2hstring(artist));
}

void on_media_session_playback_state_change(
    const capi::CMediaSessionPlaybackState state) {
  return sServo->Delegate().OnServoMediaSessionPlaybackStateChange(state);
}

void prompt_alert(const char *message, bool trusted) {
  sServo->Delegate().OnServoPromptAlert(char2hstring(message), trusted);
}

Servo::PromptResult prompt_ok_cancel(const char *message, bool trusted) {
  return sServo->Delegate().OnServoPromptOkCancel(char2hstring(message),
                                                  trusted);
}

Servo::PromptResult prompt_yes_no(const char *message, bool trusted) {
  return sServo->Delegate().OnServoPromptYesNo(char2hstring(message), trusted);
}

const char *prompt_input(const char *message, const char *default,
                         bool trusted) {
  auto input = sServo->Delegate().OnServoPromptInput(
      char2hstring(message), char2hstring(default), trusted);
  if (input.has_value()) {
    return *hstring2char(*input);
  } else {
    return nullptr;
  }
}

Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
             float dpi, ServoDelegate &aDelegate)
    : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {

  capi::CInitOptions o;
  hstring defaultPrefs = L" --pref dom.webxr.enabled";
  o.args = *hstring2char(args + defaultPrefs);
  o.url = *hstring2char(url);
  o.width = mWindowWidth;
  o.height = mWindowHeight;
  o.density = dpi;
  o.enable_subpixel_text_antialiasing = false;
  o.vr_pointer = NULL;

  // 7 filter modules.
  /* Sample list of servo modules to filter.
  static char *pfilters[] = {
          "servo",
          "simpleservo",
          "simpleservo::jniapi",
          "simpleservo::gl_glue::egl",
          // Show JS errors by default.
          "script::dom::bindings::error",
          // Show GL errors by default.
          "canvas::webgl_thread",
          "compositing::compositor",
          "constellation::constellation",
  };
  */

  // Example Call when *pfilters[] is used:
  // o.vslogger_mod_list = pfilters; // servo log modules
  // o.vslogger_mod_size = sizeof(pfilters) / sizeof(pfilters[0]); //
  // Important: Number of modules in pfilters
  o.vslogger_mod_list = NULL;
  o.vslogger_mod_size = 0;

  sServo = this; // FIXME;

  capi::CHostCallbacks c;
  c.flush = &flush;
  c.make_current = &make_current;
  c.on_load_started = &on_load_started;
  c.on_load_ended = &on_load_ended;
  c.on_title_changed = &on_title_changed;
  c.on_url_changed = &on_url_changed;
  c.on_history_changed = &on_history_changed;
  c.on_animating_changed = &on_animating_changed;
  c.on_shutdown_complete = &on_shutdown_complete;
  c.on_allow_navigation = &on_allow_navigation;
  c.on_ime_state_changed = &on_ime_state_changed;
  c.get_clipboard_contents = &get_clipboard_contents;
  c.set_clipboard_contents = &set_clipboard_contents;
  c.on_media_session_metadata = &on_media_session_metadata;
  c.on_media_session_playback_state_change =
      &on_media_session_playback_state_change;
  c.prompt_alert = &prompt_alert;
  c.prompt_ok_cancel = &prompt_ok_cancel;
  c.prompt_yes_no = &prompt_yes_no;
  c.prompt_input = &prompt_input;

  capi::register_panic_handler(&on_panic);

  capi::init_with_egl(o, &wakeup, c);
}

Servo::~Servo() { sServo = nullptr; }

winrt::hstring char2hstring(const char *c_str) {
  // FIXME: any better way of doing this?
  auto str = std::string(c_str);
  int size_needed =
      MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
  std::wstring str2(size_needed, 0);
  MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &str2[0],
                      size_needed);
  winrt::hstring str3{str2};
  return str3;
}

std::unique_ptr<char *> hstring2char(hstring hstr) {
  const wchar_t *wc = hstr.c_str();
  size_t size = hstr.size() + 1;
  char *str = new char[size];
  size_t converted = 0;
  wcstombs_s(&converted, str, size, wc, hstr.size());
  return std::make_unique<char *>(str);
}

} // namespace winrt::servo
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: addxmltostorageoptions.cxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: jp $ $Date: 2000-11-29 12:15:02 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

//_________________________________________________________________________________________________________________
//  includes
//_________________________________________________________________________________________________________________

#include "addxmltostorageoptions.hxx"

#ifndef _UTL_CONFIGMGR_HXX_
#include <unotools/configmgr.hxx>
#endif
#ifndef _UTL_CONFIGITEM_HXX_
#include <unotools/configitem.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _TOOLS_STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
#include <com/sun/star/uno/Any.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
#endif

//_________________________________________________________________________________________________________________
//  namespaces
//_________________________________________________________________________________________________________________

using namespace ::utl;
using namespace ::rtl;
using namespace ::osl;
using namespace ::com::sun::star::uno;

//*****************************************************************************************************************
//  initialize static member
//  DON'T DO IT IN YOUR HEADER!
//  see definition for further informations
//*****************************************************************************************************************
SvtAddXMLToStorageOptions_Impl* SvtAddXMLToStorageOptions::m_pDataContainer = 0;
sal_Int32 SvtAddXMLToStorageOptions::m_nRefCount = 0;

//_________________________________________________________________________________________________________________
//  private declarations!
//_________________________________________________________________________________________________________________

class SvtAddXMLToStorageOptions_Impl : public ConfigItem
{
    //-------------------------------------------------------------------------------------------------------------
    //  public methods
    //-------------------------------------------------------------------------------------------------------------

    public:

        //---------------------------------------------------------------------------------------------------------
        //  constructor / destructor
        //---------------------------------------------------------------------------------------------------------

         SvtAddXMLToStorageOptions_Impl();

        //---------------------------------------------------------------------------------------------------------
        //  overloaded methods of baseclass
        //---------------------------------------------------------------------------------------------------------

        //---------------------------------------------------------------------------------------------------------
        //  public interface
        //---------------------------------------------------------------------------------------------------------

        /*-****************************************************************************************************//**
            @short      access method to get internal values
            @descr      These method give us a chance to regulate acces to ouer internal values.
                        It's not used in the moment - but it's possible for the feature!

            @seealso    -

            @param      -
            @return     -

            @onerror    -
        *//*-*****************************************************************************************************/

        sal_Bool IsWriter_Add_XML_to_Storage() const    { return bAddXmlToStg_Writer; }
        sal_Bool IsCalc_Add_XML_to_Storage() const      { return bAddXmlToStg_Calc; }
        sal_Bool IsImpress_Add_XML_to_Storage() const   { return bAddXmlToStg_Impress; }
        sal_Bool IsDraw_Add_XML_to_Storage() const      { return bAddXmlToStg_Draw; }

    //-------------------------------------------------------------------------------------------------------------
    //  private methods
    //-------------------------------------------------------------------------------------------------------------

    private:

        /*-****************************************************************************************************//**
            @short      return list of key names of ouer configuration management which represent oue module tree
            @descr      These methods return a static const list of key names. We need it to get needed values from our
                        configuration management.

            @seealso    -

            @param      -
            @return     A list of needed configuration keys is returned.

            @onerror    -
        *//*-*****************************************************************************************************/

        static Sequence< OUString > GetPropertyNames();

    //-------------------------------------------------------------------------------------------------------------
    //  private member
    //-------------------------------------------------------------------------------------------------------------

    private:

        sal_Bool bAddXmlToStg_Writer,
                 bAddXmlToStg_Calc,
                 bAddXmlToStg_Impress,
                 bAddXmlToStg_Draw;
};

//_________________________________________________________________________________________________________________
//  definitions
//_________________________________________________________________________________________________________________

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions_Impl::SvtAddXMLToStorageOptions_Impl()
    // Init baseclasses first
    :   ConfigItem( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
                        "Office.Common/AddXMLToStorage"))),
    // Init member then.
    bAddXmlToStg_Writer( FALSE ),
    bAddXmlToStg_Calc( FALSE ),
    bAddXmlToStg_Impress( FALSE ),
    bAddXmlToStg_Draw( FALSE )
{
    // Use our static list of configuration keys to get his values.
    Sequence< OUString > seqNames = GetPropertyNames();
    Sequence< Any > seqValues = GetProperties( seqNames );

    // Copy values from list in right order to ouer internal member.
    sal_Int32 nPropertyCount = seqValues.getLength();
    const Any* pValue = seqValues.getConstArray();
    for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty, ++pValue )
        if( pValue->hasValue() )

            switch( nProperty )
            {
            case 0:
                *pValue >>= bAddXmlToStg_Writer;
                break;
            case 1:
                *pValue >>= bAddXmlToStg_Calc;
                break;
            case 2:
                *pValue >>= bAddXmlToStg_Impress;
                break;
            case 3:
                *pValue >>= bAddXmlToStg_Draw;
                break;
            }
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Sequence< OUString > SvtAddXMLToStorageOptions_Impl::GetPropertyNames()
{
    // Build static list of configuration key names.
    static const sal_Char* pProperties[] =
    {
        "Writer",
        "Calc",
        "Impress",
        "Draw"
    };

    const sal_uInt16 nCnt = sizeof(pProperties) / sizeof( pProperties[0] );
    Sequence<OUString> aNames( nCnt );
    OUString* pNames = aNames.getArray();
    for( sal_uInt16 n = 0; n < nCnt; ++n )
        pNames[ n ] = OUString::createFromAscii( pProperties[ n ] );
    return aNames;
}

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions::SvtAddXMLToStorageOptions()
{
    // Global access, must be guarded (multithreading!).
    MutexGuard aGuard( GetOwnStaticMutex() );
    // Increase ouer refcount ...
    ++m_nRefCount;
    // ... and initialize ouer data container only if it not already exist!
    if( !m_pDataContainer )
        m_pDataContainer = new SvtAddXMLToStorageOptions_Impl;
}

//*****************************************************************************************************************
//  destructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions::~SvtAddXMLToStorageOptions()
{
    // Global access, must be guarded (multithreading!)
    MutexGuard aGuard( GetOwnStaticMutex() );
    // Decrease ouer refcount.
    // If last instance was deleted ...
    // we must destroy ouer static data container!
    if( !--m_nRefCount )
        delete m_pDataContainer, m_pDataContainer = 0;
}

sal_Bool SvtAddXMLToStorageOptions::IsWriter_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsWriter_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsCalc_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsCalc_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsImpress_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsImpress_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsDraw_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsDraw_Add_XML_to_Storage();
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Mutex& SvtAddXMLToStorageOptions::GetOwnStaticMutex()
{
    // Initialize static mutex only for one time!
    static Mutex* pMutex = NULL;
    // If these method first called (Mutex not already exist!) ...
    if( pMutex == NULL )
    {
        // ... we must create a new one. Protect follow code with the global mutex -
        // It must be - we create a static variable!
        MutexGuard aGuard( Mutex::getGlobalMutex() );
        // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
        if( pMutex == NULL )
        {
            // Create the new mutex and set it for return on static variable.
            static Mutex aMutex;
            pMutex = &aMutex;
        }
    }
    // Return new created or already existing mutex object.
    return *pMutex;
}
<commit_msg>INTEGRATION: CWS ooo20040509 (1.1.584); FILE MERGED 2004/05/06 14:04:24 waratah 1.1.584.1: Bracket pragma not valid for gcc<commit_after>/*************************************************************************
 *
 *  $RCSfile: addxmltostorageoptions.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2004-06-16 10:06:01 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef GCC
#pragma hdrstop
#endif

//_________________________________________________________________________________________________________________
//  includes
//_________________________________________________________________________________________________________________

#include "addxmltostorageoptions.hxx"

#ifndef _UTL_CONFIGMGR_HXX_
#include <unotools/configmgr.hxx>
#endif
#ifndef _UTL_CONFIGITEM_HXX_
#include <unotools/configitem.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _TOOLS_STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
#include <com/sun/star/uno/Any.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
#endif

//_________________________________________________________________________________________________________________
//  namespaces
//_________________________________________________________________________________________________________________

using namespace ::utl;
using namespace ::rtl;
using namespace ::osl;
using namespace ::com::sun::star::uno;

//*****************************************************************************************************************
//  initialize static member
//  DON'T DO IT IN YOUR HEADER!
//  see definition for further informations
//*****************************************************************************************************************
SvtAddXMLToStorageOptions_Impl* SvtAddXMLToStorageOptions::m_pDataContainer = 0;
sal_Int32 SvtAddXMLToStorageOptions::m_nRefCount = 0;

//_________________________________________________________________________________________________________________
//  private declarations!
//_________________________________________________________________________________________________________________

class SvtAddXMLToStorageOptions_Impl : public ConfigItem
{
    //-------------------------------------------------------------------------------------------------------------
    //  public methods
    //-------------------------------------------------------------------------------------------------------------

    public:

        //---------------------------------------------------------------------------------------------------------
        //  constructor / destructor
        //---------------------------------------------------------------------------------------------------------

         SvtAddXMLToStorageOptions_Impl();

        //---------------------------------------------------------------------------------------------------------
        //  overloaded methods of baseclass
        //---------------------------------------------------------------------------------------------------------

        //---------------------------------------------------------------------------------------------------------
        //  public interface
        //---------------------------------------------------------------------------------------------------------

        /*-****************************************************************************************************//**
            @short      access method to get internal values
            @descr      These method give us a chance to regulate acces to ouer internal values.
                        It's not used in the moment - but it's possible for the feature!

            @seealso    -

            @param      -
            @return     -

            @onerror    -
        *//*-*****************************************************************************************************/

        sal_Bool IsWriter_Add_XML_to_Storage() const    { return bAddXmlToStg_Writer; }
        sal_Bool IsCalc_Add_XML_to_Storage() const      { return bAddXmlToStg_Calc; }
        sal_Bool IsImpress_Add_XML_to_Storage() const   { return bAddXmlToStg_Impress; }
        sal_Bool IsDraw_Add_XML_to_Storage() const      { return bAddXmlToStg_Draw; }

    //-------------------------------------------------------------------------------------------------------------
    //  private methods
    //-------------------------------------------------------------------------------------------------------------

    private:

        /*-****************************************************************************************************//**
            @short      return list of key names of ouer configuration management which represent oue module tree
            @descr      These methods return a static const list of key names. We need it to get needed values from our
                        configuration management.

            @seealso    -

            @param      -
            @return     A list of needed configuration keys is returned.

            @onerror    -
        *//*-*****************************************************************************************************/

        static Sequence< OUString > GetPropertyNames();

    //-------------------------------------------------------------------------------------------------------------
    //  private member
    //-------------------------------------------------------------------------------------------------------------

    private:

        sal_Bool bAddXmlToStg_Writer,
                 bAddXmlToStg_Calc,
                 bAddXmlToStg_Impress,
                 bAddXmlToStg_Draw;
};

//_________________________________________________________________________________________________________________
//  definitions
//_________________________________________________________________________________________________________________

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions_Impl::SvtAddXMLToStorageOptions_Impl()
    // Init baseclasses first
    :   ConfigItem( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
                        "Office.Common/AddXMLToStorage"))),
    // Init member then.
    bAddXmlToStg_Writer( FALSE ),
    bAddXmlToStg_Calc( FALSE ),
    bAddXmlToStg_Impress( FALSE ),
    bAddXmlToStg_Draw( FALSE )
{
    // Use our static list of configuration keys to get his values.
    Sequence< OUString > seqNames = GetPropertyNames();
    Sequence< Any > seqValues = GetProperties( seqNames );

    // Copy values from list in right order to ouer internal member.
    sal_Int32 nPropertyCount = seqValues.getLength();
    const Any* pValue = seqValues.getConstArray();
    for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty, ++pValue )
        if( pValue->hasValue() )

            switch( nProperty )
            {
            case 0:
                *pValue >>= bAddXmlToStg_Writer;
                break;
            case 1:
                *pValue >>= bAddXmlToStg_Calc;
                break;
            case 2:
                *pValue >>= bAddXmlToStg_Impress;
                break;
            case 3:
                *pValue >>= bAddXmlToStg_Draw;
                break;
            }
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Sequence< OUString > SvtAddXMLToStorageOptions_Impl::GetPropertyNames()
{
    // Build static list of configuration key names.
    static const sal_Char* pProperties[] =
    {
        "Writer",
        "Calc",
        "Impress",
        "Draw"
    };

    const sal_uInt16 nCnt = sizeof(pProperties) / sizeof( pProperties[0] );
    Sequence<OUString> aNames( nCnt );
    OUString* pNames = aNames.getArray();
    for( sal_uInt16 n = 0; n < nCnt; ++n )
        pNames[ n ] = OUString::createFromAscii( pProperties[ n ] );
    return aNames;
}

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions::SvtAddXMLToStorageOptions()
{
    // Global access, must be guarded (multithreading!).
    MutexGuard aGuard( GetOwnStaticMutex() );
    // Increase ouer refcount ...
    ++m_nRefCount;
    // ... and initialize ouer data container only if it not already exist!
    if( !m_pDataContainer )
        m_pDataContainer = new SvtAddXMLToStorageOptions_Impl;
}

//*****************************************************************************************************************
//  destructor
//*****************************************************************************************************************
SvtAddXMLToStorageOptions::~SvtAddXMLToStorageOptions()
{
    // Global access, must be guarded (multithreading!)
    MutexGuard aGuard( GetOwnStaticMutex() );
    // Decrease ouer refcount.
    // If last instance was deleted ...
    // we must destroy ouer static data container!
    if( !--m_nRefCount )
        delete m_pDataContainer, m_pDataContainer = 0;
}

sal_Bool SvtAddXMLToStorageOptions::IsWriter_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsWriter_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsCalc_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsCalc_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsImpress_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsImpress_Add_XML_to_Storage();
}
sal_Bool SvtAddXMLToStorageOptions::IsDraw_Add_XML_to_Storage() const
{
    MutexGuard aGuard( GetOwnStaticMutex() );
    return m_pDataContainer->IsDraw_Add_XML_to_Storage();
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Mutex& SvtAddXMLToStorageOptions::GetOwnStaticMutex()
{
    // Initialize static mutex only for one time!
    static Mutex* pMutex = NULL;
    // If these method first called (Mutex not already exist!) ...
    if( pMutex == NULL )
    {
        // ... we must create a new one. Protect follow code with the global mutex -
        // It must be - we create a static variable!
        MutexGuard aGuard( Mutex::getGlobalMutex() );
        // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
        if( pMutex == NULL )
        {
            // Create the new mutex and set it for return on static variable.
            static Mutex aMutex;
            pMutex = &aMutex;
        }
    }
    // Return new created or already existing mutex object.
    return *pMutex;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: customizeaddresslistdialog.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2007-09-27 11:30:34 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"

#ifdef SW_DLLIMPLEMENTATION
#undef SW_DLLIMPLEMENTATION
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif

#ifndef _CUSTOMIZEADDRESSLISTDIALOG_HXX
#include <customizeaddresslistdialog.hxx>
#endif
#ifndef _CREATEADDRESSLISTDIALOG_HXX
#include <createaddresslistdialog.hxx>
#endif
#ifndef _SV_SCRBAR_HXX
#include <vcl/scrbar.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#include <customizeaddresslistdialog.hrc>
#include <dbui.hrc>
#include <helpid.h>

/*-- 13.04.2004 14:27:21---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
        Window* pParent, const SwCSVData& rOldData) :
    SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST)),
#ifdef MSC
#pragma warning (disable : 4355)
#endif
    m_aFieldsFT( this, SW_RES(    FT_FIELDS)),
    m_aFieldsLB( this, SW_RES(    LB_FIELDS)),
    m_aAddPB( this, SW_RES(       PB_ADD)),
    m_aDeletePB( this, SW_RES(    PB_DELETE)),
    m_aRenamePB( this, SW_RES(    PB_RENAME)),
    m_aUpPB( this, SW_RES(        PB_UP)),
    m_aDownPB( this, SW_RES(      PB_DOWN)),
    m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
    m_aOK( this, SW_RES(          PB_OK)),
    m_aCancel( this, SW_RES(      PB_CANCEL)),
    m_aHelp( this, SW_RES(        PB_HELP)),
#ifdef MSC
#pragma warning (default : 4355)
#endif
    m_pNewData( new SwCSVData(rOldData))
{
    FreeResource();
    m_aFieldsLB.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
    Link aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
    m_aAddPB.SetClickHdl(aAddRenameLk);
    m_aRenamePB.SetClickHdl(aAddRenameLk);
    m_aDeletePB.SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
    Link aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
    m_aUpPB.SetClickHdl(aUpDownLk);
    m_aDownPB.SetClickHdl(aUpDownLk);

    ::std::vector< ::rtl::OUString >::iterator aHeaderIter;

    for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
                aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
        m_aFieldsLB.InsertEntry(*aHeaderIter);

    m_aFieldsLB.SelectEntryPos(0);
    UpdateButtons();
}
/*-- 13.04.2004 14:34:07---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
{
}

/*-- 12.08.2004 12:58:00---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl, ListBox*, EMPTYARG)
{
    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:14---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
{
    bool bRename = pButton == &m_aRenamePB;
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    if(nPos == LISTBOX_ENTRY_NOTFOUND)
        nPos = 0;

    SwAddRenameEntryDialog* pDlg =
            new SwAddRenameEntryDialog(pButton, bRename, m_pNewData->aDBColumnHeaders);
    if(bRename)
    {
        String aTemp = m_aFieldsLB.GetEntry(nPos);
        pDlg->SetFieldName(aTemp);
    }
    if(RET_OK == pDlg->Execute())
    {
        String sNew = pDlg->GetFieldName();
        if(bRename)
        {
            m_pNewData->aDBColumnHeaders[nPos] = sNew;
            m_aFieldsLB.RemoveEntry(nPos);
        }
        else
        {
            if ( m_aFieldsLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
                ++nPos; // append the new entry behind the selected
            //add the new column
            m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
            //add a new entry into all data arrays
            String sTemp;
            ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
            for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
                aDataIter->insert(aDataIter->begin() + nPos, sTemp);

        }

        m_aFieldsLB.InsertEntry(sNew, nPos);
        m_aFieldsLB.SelectEntryPos(nPos);
    }
    delete pDlg;
    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:14---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, DeleteHdl_Impl, PushButton*, EMPTYARG)
{
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    m_aFieldsLB.RemoveEntry(m_aFieldsLB.GetSelectEntryPos());
    m_aFieldsLB.SelectEntryPos(nPos > m_aFieldsLB.GetEntryCount() - 1 ? nPos - 1 : nPos);

    //remove the column
    m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
    //remove the data
    ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
    for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
        aDataIter->erase(aDataIter->begin() + nPos);

    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:15---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
{
    USHORT nPos;
    USHORT nOldPos = nPos = m_aFieldsLB.GetSelectEntryPos();
    String aTemp = m_aFieldsLB.GetEntry(nPos);
    m_aFieldsLB.RemoveEntry( nPos );
    if(pButton == &m_aUpPB)
        --nPos;
    else
        ++nPos;
    m_aFieldsLB.InsertEntry(aTemp, nPos);
    m_aFieldsLB.SelectEntryPos(nPos);
    //align m_pNewData
    ::rtl::OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
    m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
    m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
    ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
    for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
    {
        ::rtl::OUString sData = (*aDataIter)[nOldPos];
        aDataIter->erase(aDataIter->begin() + nOldPos);
        aDataIter->insert(aDataIter->begin() + nPos, sData);
    }

    UpdateButtons();
    return 0;
}
/*-- 19.04.2004 14:51:49---------------------------------------------------

  -----------------------------------------------------------------------*/
void SwCustomizeAddressListDialog::UpdateButtons()
{
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    USHORT nEntries = m_aFieldsLB.GetEntryCount();
    m_aUpPB.Enable(nPos > 0 && nEntries > 0);
    m_aDownPB.Enable(nPos < nEntries -1);
    m_aDeletePB.Enable(nEntries > 0);
    m_aRenamePB.Enable(nEntries > 0);
}
/*-- 19.04.2004 14:51:49---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCSVData*    SwCustomizeAddressListDialog::GetNewData()
{
    return m_pNewData;
}

/*-- 13.04.2004 13:48:41---------------------------------------------------

  -----------------------------------------------------------------------*/
SwAddRenameEntryDialog::SwAddRenameEntryDialog(
        Window* pParent, bool bRename, const ::std::vector< ::rtl::OUString >& rCSVHeader) :
    SfxModalDialog(pParent, SW_RES(DLG_MM_ADD_RENAME_ENTRY)),
#ifdef MSC
#pragma warning (disable : 4355)
#endif
    m_aFieldNameFT( this, SW_RES( FT_FIELDNAME)),
    m_aFieldNameED( this, SW_RES( ED_FIELDNAME)),
    m_aOK( this, SW_RES(          PB_OK)),
    m_aCancel( this, SW_RES(      PB_CANCEL)),
    m_aHelp( this, SW_RES(        PB_HELP)),
#ifdef MSC
#pragma warning (default : 4355)
#endif
    m_rCSVHeader(rCSVHeader)
{
    if(bRename)
        SetText(String(SW_RES(ST_RENAME_TITLE)));
    else
        m_aOK.SetText(String(SW_RES(ST_ADD_BUTTON)));
    FreeResource();
    m_aFieldNameED.SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
    ModifyHdl_Impl( &m_aFieldNameED );
}
/*-- 13.04.2004 13:48:41---------------------------------------------------

  -----------------------------------------------------------------------*/
SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
{
}
/*-- 19.04.2004 15:31:34---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
{
    ::rtl::OUString sEntry = pEdit->GetText();
    BOOL bFound = sEntry.getLength() ? FALSE : TRUE;

    if(!bFound)
    {
        ::std::vector< ::rtl::OUString >::const_iterator aHeaderIter;
        for(aHeaderIter = m_rCSVHeader.begin();
                    aHeaderIter != m_rCSVHeader.end();
                    ++aHeaderIter)
            if(*aHeaderIter == sEntry)
            {
                bFound = TRUE;
                break;
            }
    }
    m_aOK.Enable(!bFound);
    return 0;
}
<commit_msg>INTEGRATION: CWS changefileheader (1.9.242); FILE MERGED 2008/04/01 15:58:32 thb 1.9.242.3: #i85898# Stripping all external header guards 2008/04/01 12:55:06 thb 1.9.242.2: #i85898# Stripping all external header guards 2008/03/31 16:57:00 rt 1.9.242.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: customizeaddresslistdialog.cxx,v $
 * $Revision: 1.10 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"

#ifdef SW_DLLIMPLEMENTATION
#undef SW_DLLIMPLEMENTATION
#endif
#include <swtypes.hxx>
#include <customizeaddresslistdialog.hxx>
#include <createaddresslistdialog.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/msgbox.hxx>
#include <customizeaddresslistdialog.hrc>
#include <dbui.hrc>
#include <helpid.h>

/*-- 13.04.2004 14:27:21---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
        Window* pParent, const SwCSVData& rOldData) :
    SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST)),
#ifdef MSC
#pragma warning (disable : 4355)
#endif
    m_aFieldsFT( this, SW_RES(    FT_FIELDS)),
    m_aFieldsLB( this, SW_RES(    LB_FIELDS)),
    m_aAddPB( this, SW_RES(       PB_ADD)),
    m_aDeletePB( this, SW_RES(    PB_DELETE)),
    m_aRenamePB( this, SW_RES(    PB_RENAME)),
    m_aUpPB( this, SW_RES(        PB_UP)),
    m_aDownPB( this, SW_RES(      PB_DOWN)),
    m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
    m_aOK( this, SW_RES(          PB_OK)),
    m_aCancel( this, SW_RES(      PB_CANCEL)),
    m_aHelp( this, SW_RES(        PB_HELP)),
#ifdef MSC
#pragma warning (default : 4355)
#endif
    m_pNewData( new SwCSVData(rOldData))
{
    FreeResource();
    m_aFieldsLB.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
    Link aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
    m_aAddPB.SetClickHdl(aAddRenameLk);
    m_aRenamePB.SetClickHdl(aAddRenameLk);
    m_aDeletePB.SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
    Link aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
    m_aUpPB.SetClickHdl(aUpDownLk);
    m_aDownPB.SetClickHdl(aUpDownLk);

    ::std::vector< ::rtl::OUString >::iterator aHeaderIter;

    for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
                aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
        m_aFieldsLB.InsertEntry(*aHeaderIter);

    m_aFieldsLB.SelectEntryPos(0);
    UpdateButtons();
}
/*-- 13.04.2004 14:34:07---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
{
}

/*-- 12.08.2004 12:58:00---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl, ListBox*, EMPTYARG)
{
    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:14---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
{
    bool bRename = pButton == &m_aRenamePB;
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    if(nPos == LISTBOX_ENTRY_NOTFOUND)
        nPos = 0;

    SwAddRenameEntryDialog* pDlg =
            new SwAddRenameEntryDialog(pButton, bRename, m_pNewData->aDBColumnHeaders);
    if(bRename)
    {
        String aTemp = m_aFieldsLB.GetEntry(nPos);
        pDlg->SetFieldName(aTemp);
    }
    if(RET_OK == pDlg->Execute())
    {
        String sNew = pDlg->GetFieldName();
        if(bRename)
        {
            m_pNewData->aDBColumnHeaders[nPos] = sNew;
            m_aFieldsLB.RemoveEntry(nPos);
        }
        else
        {
            if ( m_aFieldsLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
                ++nPos; // append the new entry behind the selected
            //add the new column
            m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
            //add a new entry into all data arrays
            String sTemp;
            ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
            for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
                aDataIter->insert(aDataIter->begin() + nPos, sTemp);

        }

        m_aFieldsLB.InsertEntry(sNew, nPos);
        m_aFieldsLB.SelectEntryPos(nPos);
    }
    delete pDlg;
    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:14---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, DeleteHdl_Impl, PushButton*, EMPTYARG)
{
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    m_aFieldsLB.RemoveEntry(m_aFieldsLB.GetSelectEntryPos());
    m_aFieldsLB.SelectEntryPos(nPos > m_aFieldsLB.GetEntryCount() - 1 ? nPos - 1 : nPos);

    //remove the column
    m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
    //remove the data
    ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
    for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
        aDataIter->erase(aDataIter->begin() + nPos);

    UpdateButtons();
    return 0;
}
/*-- 13.04.2004 15:02:15---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
{
    USHORT nPos;
    USHORT nOldPos = nPos = m_aFieldsLB.GetSelectEntryPos();
    String aTemp = m_aFieldsLB.GetEntry(nPos);
    m_aFieldsLB.RemoveEntry( nPos );
    if(pButton == &m_aUpPB)
        --nPos;
    else
        ++nPos;
    m_aFieldsLB.InsertEntry(aTemp, nPos);
    m_aFieldsLB.SelectEntryPos(nPos);
    //align m_pNewData
    ::rtl::OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
    m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
    m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
    ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
    for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
    {
        ::rtl::OUString sData = (*aDataIter)[nOldPos];
        aDataIter->erase(aDataIter->begin() + nOldPos);
        aDataIter->insert(aDataIter->begin() + nPos, sData);
    }

    UpdateButtons();
    return 0;
}
/*-- 19.04.2004 14:51:49---------------------------------------------------

  -----------------------------------------------------------------------*/
void SwCustomizeAddressListDialog::UpdateButtons()
{
    USHORT nPos = m_aFieldsLB.GetSelectEntryPos();
    USHORT nEntries = m_aFieldsLB.GetEntryCount();
    m_aUpPB.Enable(nPos > 0 && nEntries > 0);
    m_aDownPB.Enable(nPos < nEntries -1);
    m_aDeletePB.Enable(nEntries > 0);
    m_aRenamePB.Enable(nEntries > 0);
}
/*-- 19.04.2004 14:51:49---------------------------------------------------

  -----------------------------------------------------------------------*/
SwCSVData*    SwCustomizeAddressListDialog::GetNewData()
{
    return m_pNewData;
}

/*-- 13.04.2004 13:48:41---------------------------------------------------

  -----------------------------------------------------------------------*/
SwAddRenameEntryDialog::SwAddRenameEntryDialog(
        Window* pParent, bool bRename, const ::std::vector< ::rtl::OUString >& rCSVHeader) :
    SfxModalDialog(pParent, SW_RES(DLG_MM_ADD_RENAME_ENTRY)),
#ifdef MSC
#pragma warning (disable : 4355)
#endif
    m_aFieldNameFT( this, SW_RES( FT_FIELDNAME)),
    m_aFieldNameED( this, SW_RES( ED_FIELDNAME)),
    m_aOK( this, SW_RES(          PB_OK)),
    m_aCancel( this, SW_RES(      PB_CANCEL)),
    m_aHelp( this, SW_RES(        PB_HELP)),
#ifdef MSC
#pragma warning (default : 4355)
#endif
    m_rCSVHeader(rCSVHeader)
{
    if(bRename)
        SetText(String(SW_RES(ST_RENAME_TITLE)));
    else
        m_aOK.SetText(String(SW_RES(ST_ADD_BUTTON)));
    FreeResource();
    m_aFieldNameED.SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
    ModifyHdl_Impl( &m_aFieldNameED );
}
/*-- 13.04.2004 13:48:41---------------------------------------------------

  -----------------------------------------------------------------------*/
SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
{
}
/*-- 19.04.2004 15:31:34---------------------------------------------------

  -----------------------------------------------------------------------*/
IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
{
    ::rtl::OUString sEntry = pEdit->GetText();
    BOOL bFound = sEntry.getLength() ? FALSE : TRUE;

    if(!bFound)
    {
        ::std::vector< ::rtl::OUString >::const_iterator aHeaderIter;
        for(aHeaderIter = m_rCSVHeader.begin();
                    aHeaderIter != m_rCSVHeader.end();
                    ++aHeaderIter)
            if(*aHeaderIter == sEntry)
            {
                bFound = TRUE;
                break;
            }
    }
    m_aOK.Enable(!bFound);
    return 0;
}
<|endoftext|>


<commit_before>/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "absl/base/casts.h"
#include "tensorflow/compiler/xla/client/xla_builder.h"
#include "tensorflow/compiler/xla/tests/client_library_test_base.h"
#include "tensorflow/compiler/xla/tests/literal_test_util.h"
#include "tensorflow/compiler/xla/tests/test_macros.h"

namespace xla {
namespace {
class ExhaustiveF32ElementwiseOpTest
    : public ClientLibraryTestBase,
      public ::testing::WithParamInterface<std::pair<int64, int64>> {
 protected:
  ErrorSpec error_spec_{0.0001, 0.0001, /*relaxed_nans=*/true};

  template <typename EnqueueOpTy>
  void ExhaustivelyTestF32Op(EnqueueOpTy enqueue_op,
                             float (*evaluate_op)(float),
                             std::pair<int64, int64> known_incorrect_range) {
    int64 begin, end;
    std::tie(begin, end) = GetParam();
    int64 input_size = end - begin;
    LOG(INFO) << "Checking range [" << begin << ", " << end << ")";

    XlaBuilder builder(TestName());

    Literal input_literal =
        LiteralUtil::CreateFromDimensions(F32, {input_size});
    for (int64 i = begin; i < end; i++) {
      if (i >= known_incorrect_range.first &&
          i < known_incorrect_range.second) {
        // If the operation is known to be buggy on a specific input clamp that
        // input to 0 under the assumption that the op is at least correct on 0.
        input_literal.Set({i - begin}, 0.0f);
      } else {
        input_literal.Set({i - begin}, absl::bit_cast<float, int>(i));
      }
    }

    TF_ASSERT_OK_AND_ASSIGN(std::unique_ptr<GlobalData> input_data,
                            client_->TransferToServer(input_literal));

    auto input = Parameter(&builder, 0, input_literal.shape(), "input");
    enqueue_op(&builder, input);

    std::vector<float> expected_result;
    expected_result.reserve(input_size);
    for (int64 i = 0; i < input_size; i++) {
      expected_result.push_back(evaluate_op(input_literal.Get<float>({i})));
    }

    ComputeAndCompareR1<float>(&builder, expected_result, {input_data.get()},
                               error_spec_);
  }
};

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, LogF32) {
#ifdef XLA_TEST_BACKEND_CPU
  // TODO(b/73141998): The vectorized Log implementation gives results outside
  // our error spec in this range (these numbers are bitwise representations of
  // floats expressed as a zero extended int64).
  std::pair<int64, int64> known_incorrect_range = {1, 8388608};
#else
  std::pair<int64, int64> known_incorrect_range = {0, 0};
#endif

  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Log(input); }, std::log,
      known_incorrect_range);
}

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, ExpF32) {
#ifdef XLA_TEST_BACKEND_CPU
  // TODO(b/73142289): The vectorized Exp implementation gives results outside
  // our error spec in this range (these numbers are bitwise representations of
  // floats expressed as a zero extended int64):
  std::pair<int64, int64> known_incorrect_range = {1107296256 + 11583654,
                                                   1107296256 + 11629080};
#else
  std::pair<int64, int64> known_incorrect_range = {0, 0};
#endif

  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Exp(input); }, std::exp,
      known_incorrect_range);
}

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, TanhF32) {
  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Tanh(input); }, std::tanh,
      /*known_incorrect_range=*/{0, 0});
}

std::vector<std::pair<int64, int64>> CreateExhaustiveParameters() {
  // We break up the 2^32-element space into small'ish chunks to keep peak
  // memory usage low.
  std::vector<std::pair<int64, int64>> result;
  const int64 step = 1 << 25;
  for (int64 i = 0; i < (1l << 32); i += step) {
    result.push_back({i, i + step});
  }
  return result;
}

INSTANTIATE_TEST_CASE_P(ExhaustiveF32ElementwiseOpTestInstance,
                        ExhaustiveF32ElementwiseOpTest,
                        ::testing::ValuesIn(CreateExhaustiveParameters()));
}  // namespace
}  // namespace xla
<commit_msg>[XLA] Speed up exhaustive_f32_elementwise_op_test.<commit_after>/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "absl/base/casts.h"
#include "tensorflow/compiler/xla/client/xla_builder.h"
#include "tensorflow/compiler/xla/tests/client_library_test_base.h"
#include "tensorflow/compiler/xla/tests/literal_test_util.h"
#include "tensorflow/compiler/xla/tests/test_macros.h"

namespace xla {
namespace {
class ExhaustiveF32ElementwiseOpTest
    : public ClientLibraryTestBase,
      public ::testing::WithParamInterface<std::pair<int64, int64>> {
 protected:
  ErrorSpec error_spec_{0.0001, 0.0001, /*relaxed_nans=*/true};

  template <typename EnqueueOpTy>
  void ExhaustivelyTestF32Op(EnqueueOpTy enqueue_op,
                             float (*evaluate_op)(float),
                             std::pair<int64, int64> known_incorrect_range) {
    int64 begin, end;
    std::tie(begin, end) = GetParam();
    int64 input_size = end - begin;
    LOG(INFO) << "Checking range [" << begin << ", " << end << ")";

    XlaBuilder builder(TestName());

    Literal input_literal =
        LiteralUtil::CreateFromDimensions(F32, {input_size});
    absl::Span<float> input_arr = input_literal.data<float>();
    for (int64 i = begin; i < end; i++) {
      if (i >= known_incorrect_range.first &&
          i < known_incorrect_range.second) {
        // If the operation is known to be buggy on a specific input clamp that
        // input to 0 under the assumption that the op is at least correct on 0.
        input_arr[i - begin] = 0;
      } else {
        input_arr[i - begin] = absl::bit_cast<float, int>(i);
      }
    }

    TF_ASSERT_OK_AND_ASSIGN(std::unique_ptr<GlobalData> input_data,
                            client_->TransferToServer(input_literal));

    auto input = Parameter(&builder, 0, input_literal.shape(), "input");
    enqueue_op(&builder, input);

    std::vector<float> expected_result;
    expected_result.reserve(input_size);
    for (int64 i = 0; i < input_size; i++) {
      expected_result.push_back(evaluate_op(input_arr[i]));
    }

    ComputeAndCompareR1<float>(&builder, expected_result, {input_data.get()},
                               error_spec_);
  }
};

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, LogF32) {
#ifdef XLA_TEST_BACKEND_CPU
  // TODO(b/73141998): The vectorized Log implementation gives results outside
  // our error spec in this range (these numbers are bitwise representations of
  // floats expressed as a zero extended int64).
  std::pair<int64, int64> known_incorrect_range = {1, 8388608};
#else
  std::pair<int64, int64> known_incorrect_range = {0, 0};
#endif

  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Log(input); }, std::log,
      known_incorrect_range);
}

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, ExpF32) {
#ifdef XLA_TEST_BACKEND_CPU
  // TODO(b/73142289): The vectorized Exp implementation gives results outside
  // our error spec in this range (these numbers are bitwise representations of
  // floats expressed as a zero extended int64):
  std::pair<int64, int64> known_incorrect_range = {1107296256 + 11583654,
                                                   1107296256 + 11629080};
#else
  std::pair<int64, int64> known_incorrect_range = {0, 0};
#endif

  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Exp(input); }, std::exp,
      known_incorrect_range);
}

XLA_TEST_P(ExhaustiveF32ElementwiseOpTest, TanhF32) {
  ExhaustivelyTestF32Op(
      [](XlaBuilder* builder, const XlaOp& input) { Tanh(input); }, std::tanh,
      /*known_incorrect_range=*/{0, 0});
}

std::vector<std::pair<int64, int64>> CreateExhaustiveParameters() {
  // We break up the 2^32-element space into small'ish chunks to keep peak
  // memory usage low.
  std::vector<std::pair<int64, int64>> result;
  const int64 step = 1 << 25;
  for (int64 i = 0; i < (1l << 32); i += step) {
    result.push_back({i, i + step});
  }
  return result;
}

INSTANTIATE_TEST_CASE_P(ExhaustiveF32ElementwiseOpTestInstance,
                        ExhaustiveF32ElementwiseOpTest,
                        ::testing::ValuesIn(CreateExhaustiveParameters()));
}  // namespace
}  // namespace xla
<|endoftext|>