// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
//
//  Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
//            (C) 2014-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
//            (C) 2020      Kuba Ober <kuba@bertec.com>
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program 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 General Public License for more details.
//
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//  SPDX-License-Identifier: GPL-2.0+

/*! \file
  This file declares the class AbsCell

  AbsCell is the Cell type that represents the field that represents the
  <code>abs()</code> and <code>cabs()</code> commands.
*/

#ifndef ABSCELL_H
#define ABSCELL_H

#include "Cell.h"
#include <memory>

/*! \file

  This file defines the class for the cell type that represents an abs(x) block.
*/

/*! A cell that represents an abs(x) block

  Once IsBrokenIntoLines(), the draw list (see GetBrokenCellCount()/
  GetBrokenCell()) expands this cell into the following individual cells
  instead of drawing it as a single 2D object:

  - The opening "abs("
  - The contents
  - The closing ")".
*/
class AbsCell final : public Cell
{
public:
  /*! \image html AbsCellGeometry.svg */
  AbsCell(GroupCell *group, Configuration *config, std::unique_ptr<Cell> &&inner);
  AbsCell(GroupCell *group, const AbsCell &cell);
  std::unique_ptr<Cell> Copy(GroupCell *group) const override;
  const CellTypeInfo &GetInfo() override;

  //! ORDER MATTERS: also used, via the default GetBrokenCellCount()/
  //! GetBrokenCell(), as this cell's broken/linear draw sequence -- "abs(",
  //! then the (possibly multi-cell) contents, then ")", unconditionally.
  size_t GetInnerCellCount() const override { return 3; }
  Cell *GetInnerCell(size_t index) const override {
    switch (index) {
    case 0:
      return m_open.get();
    case 1:
      return m_innerCell.get();
    case 2:
      return m_close.get();
    default:
      return nullptr;
    }
  }

  bool BreakUp() const override;

  void Recalculate(const AFontSize fontsize) const override;

  using Cell::SetCurrentPoint;
  void SetCurrentPoint(wxPoint point) const override;

  void Draw(wxDC *dc, wxDC *antialiassingDC) override;

  wxString ToMathML() const override;
  wxString ToMatlab() const override;
  wxString ToOMML() const override;
  wxString ToString() const override;
  wxString ToTeX() const override;
  wxString ToXML() const override;

private:
  void MakeBreakupCells();

  // The pointers below point to inner cells and must be kept contiguous.
  // ** This is the draw list order. All pointers must be the same:
  // ** either Cell * or std::unique_ptr<Cell>. NO OTHER TYPES are allowed.
  //! The cell containing the eventual "abs" and the opening parenthesis
  std::unique_ptr<Cell> m_open;
  //! The contents of the abs() command
  std::unique_ptr<Cell> m_innerCell;
  //! The cell containing the closing parenthesis
  std::unique_ptr<Cell> m_close;
  // The pointers above point to inner cells and must be kept contiguous.
};

#endif // ABSCELL_H
