view anagram/vaclgui/statwin.cpp @ 13:43d8b194fb4e

Remove unused variables.
author David A. Holland
date Tue, 31 May 2022 00:59:00 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * scon.cpp
 */

#include <ifont.hpp>

#include "data.h"
#include "dict.h"
#include "dspar.hpp"
#include "error.h"
#include "statwin.hpp"
#include "p.h"
#include "pgg24-defs.h"
#include "pgg24.h"
#include "q1glbl.h"
#include "q5.h"

//#define INCLUDE_LOGGING
#include "log.h"


static int nparts;
static int errorCount;

static int sconConstructorCalls = 0;
static int sconDestructorCalls = 0;


StatisticsWindow::Parameter StatisticsWindow::parameter[8] = {
  {"Lines scanned",     &pgcb.line},
  {"Tokens identified", (int *)&ntkns},
  {"Rules identified",  (int *)&nforms},
  {"Partition sets",    (int *)&nparts},
  {"States defined",    (int *)&nits},
  {"States analyzed",   (int *)&kits},
  {"Conflicts",         (int *)&n_conflicts},
  {"Warnings",          (int *)&errorCount},
};

Boolean StatisticsWindow::paintWindow(IPaintEvent &event) {
  LOGSECTION("StatisticsWindow::paintWindow");
  LOGV((int) this) LCV(event.rect().asString());
  event.clearBackground(ColorSpec::data.bg());
  return false;
}

IStaticText *StatisticsWindow::statisticsField(IWindow *owner) {
  IStaticText *field = new IStaticText(nextChildId(), owner, owner);
  field->setAlignment(IStaticText::centerLeft);
  field->setFont(FontSpec::dataTable);
  field->setBackgroundColor(ColorSpec::data.bg());
  field->setForegroundColor(ColorSpec::data.fg());
  return field;
}

void StatisticsWindow::resize() {
  LOGSECTION("StatisticsWindow::resize");
  IFont f = FontSpec::dataTable;
  int nameWidth = f.textWidth("Tokens Identified");
  int height = f.maxSize().height();
  int valueWidth = f.textWidth("00000");
  LOGV(height) LCV(nameWidth) LCV(valueWidth);
  ISize nameSize(nameWidth, height);
  ISize valueSize(valueWidth, height);
  int i;
  for (i = 0; i < nLines; i++) {
    line[i].name->setMinimumSize(nameSize);
    line[i].value->setMinimumSize(valueSize);
  }
  ISize frameSize = frameRectFor(clientArea.minimumSize()).size();
  LOGV(frameSize.asString());
  sizeTo(frameSize);
}

void StatisticsWindow::onColorChange() {
  setBackgroundColor(ColorSpec::data.bg());
  int i;
  for (i = 0; i < nLines; i++) {
    line[i].name->setBackgroundColor(ColorSpec::data.bg());
    line[i].name->setForegroundColor(ColorSpec::data.fg());
    line[i].value->setBackgroundColor(ColorSpec::data.bg());
    line[i].value->setForegroundColor(ColorSpec::data.fg());
  }
  refresh();
}

void StatisticsWindow::onFontChange() {
  LOGSECTION("StatisticsWindow::onFontChange");
  int i;
  for (i = 0; i < nLines; i++) {
    line[i].name->setFont(FontSpec::dataTable);
    line[i].value->setFont(FontSpec::dataTable);
  }
  IFont f = FontSpec::dataTable;
  int margin = f.avgCharWidth();
  clientArea.setColumnWidth(1,margin);
  clientArea.setColumnWidth(4,3*margin);
  clientArea.setColumnWidth(7,margin);
  clientArea.setRowHeight(1, margin);
  clientArea.setRowHeight(6, margin);
  resize();
  refresh();
}

StatisticsWindow::~StatisticsWindow() {
  LOGSECTION("StatisticsWindow::~StatisticsWindow");
  IPaintHandler::stopHandlingEventsFor(&clientArea);
  LOGS("Handler detached") LCV((int) this);
  int i;
  for (i = 0; i < nLines; i++) {
    LOGS("Delete nameDemon") LCV((int) this);
    delete nameDemon[i];
    delete line[i].name;
    LOGS("Delete valueDemon") LCV((int) this);
    delete valueDemon[i];
    delete line[i].value;
    LOGS("Demons deleted") LCV(i);
  }
  sconDestructorCalls++;
}

StatisticsWindow::StatisticsWindow()
  : AgFrame(IFrameWindow::dialogBorder
            | dialogBackground
            | IFrameWindow::systemMenu)
  , clientArea(nextChildId(), this, this, IRectangle(),
	       IMultiCellCanvas::classDefaultStyle | IWindow::clipChildren)
  , dataColorChange(this, onColorChange)
  , fontChange(this, onFontChange)
  , helpDemon(&clientArea, "Statistical Summary")
{
  LOGSECTION("StatisticsWindow::StatisticsWindow");

  IPaintHandler::handleEventsFor(&clientArea);
  setClient(&clientArea);
  char buf[1000];
  sprintf(buf, "AnaGram : %s", simple_file_name.pointer());
  windowTitle.setObjectText(buf);
  windowTitle.setViewText("Statistical Summary");
  registerTitle("Statistical Summary");
  syntaxDependent = 1;
  helpCursorSupported = 1;
  dataColorChange.attach(&ColorSpec::data);
  fontChange.attach(&FontSpec::dataTable);

  setBackgroundColor(ColorSpec::data.bg());

  IFont f = FontSpec::dataTable;
  int margin = f.avgCharWidth();
  int i;
  for (i = 0; i < nLines; i++) {
    line[i].name = statisticsField(&clientArea);
    line[i].name->setAlignment(IStaticText::centerLeft);
    line[i].name->setText(parameter[i].name);

    line[i].value = statisticsField(&clientArea);
    line[i].value->setAlignment(IStaticText::centerRight);
    char buf[100];
    sprintf(buf, "%d", *parameter[i].value);
    line[i].value->setText(buf);
    nameDemon[i] = new HelpDemon(line[i].name, "Statistical Summary");
    valueDemon[i] = new HelpDemon(line[i].value, "Statistical Summary");
  }
  int j;
  for (i = 0, j = 2; i < nLines/2; i++, j++) {
    clientArea.addToCell(line[i].name, 2,j);
    clientArea.addToCell(line[i].value,3,j);
  }
  for (j = 2; i < nLines; i++, j++) {
    clientArea.addToCell(line[i].name, 5,j);
    clientArea.addToCell(line[i].value,6,j);
  }
  clientArea.setColumnWidth(1,margin);
  clientArea.setColumnWidth(4,3*margin);
  clientArea.setColumnWidth(7,margin);
  clientArea.setRowHeight(1, margin);
  clientArea.setRowHeight(6, margin);
  resize();
  sconConstructorCalls++;
}

int StatisticsWindow::updateDisplay() {
  LOGSECTION("StatisticsWindow::updateDisplay");
  nparts = part_dict->nsx - 1;
  errorCount = errorList.size();
  int changeFlag = 0;
  int i;
  for (i = 0; i < nLines; i++) {
    char buf[100];
    sprintf(buf, "%d", *parameter[i].value);
    if (line[i].value->text() == buf) {
      continue;
    }
    LOGSECTION("Update value");
    IString oldText = line[i].value->text();
    line[i].value->setText(buf);
    changeFlag = 1;
  }
  return changeFlag;
}