view anagram/vaclgui/dspar.hpp @ 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.
 *
 * dspar.hpp
 */

#ifndef DSPAR_HPP
#define DSPAR_HPP

#include <icolor.hpp>
#include <iedithdr.hpp>
#include <ifont.hpp>
//#include <ifonthdr.hpp>
#include <imcelcv.hpp>
//#include <ipainevt.hpp>
#include <ipainhdr.hpp>
#include <ipushbut.hpp>
#include <isetcv.hpp>
#include <ispinhdr.hpp>
#include <ispinnum.hpp>
#include <istattxt.hpp>
//#include <iwindow.hpp>

class AgCharStack; // from agcstack.h
class AgString; // from agstring.h
struct cint; // from cint.h
#include "action.h"
#include "agnotify.h"
#include "agstack.h"
#include "frame.hpp"
#include "base.h"

struct ColorPair {
  IColor fg;
  IColor bg;
  ColorPair() : fg(0, 0, 0), bg(255, 255, 255) {}
  ColorPair(IColor fg_, IColor bg_) : fg(fg_), bg(bg_) {}
  AgString string();
  void setValue(char *s);
};

struct ColorSpec : public AgNotifier<ColorPair> {
  ColorPair defaultValue;
  ColorSpec(IColor fg, IColor bg)
    : AgNotifier<ColorPair>(ColorPair(fg, bg))
    , defaultValue(fg, bg)
  {}
  ColorSpec(const ColorSpec &s)
    : AgNotifier<ColorPair>(s.contents)
    , defaultValue(s.defaultValue)
  {}

  void set(ColorPair &p) { contents = p; }
  ColorPair &operator = (const ColorPair &p) {
    contents = p;
    notify();
    return contents;
  }

  AgString string() { return contents.string(); }

  IColor &fg() { return contents.fg; }
  IColor &bg() { return contents.bg; }
  int reset();


  static ColorSpec defaultSetting;
  static ColorSpec dialogBackground;


  static ColorSpec syntaxFile;
  static ColorSpec traceFileHilite;
  static ColorSpec traceFileScanned;
  static ColorSpec traceFileUnscanned;

  static ColorSpec columnHead;

  static ColorSpec activeTitle;
  static ColorSpec inactiveTitle;
  static ColorSpec data;

  static ColorSpec activeCursor;
  static ColorSpec inactiveCursor;

  static ColorSpec helpText;
  static ColorSpec helpLink;
  static ColorSpec helpUsedLink;
};

//typedef AgNotifier<IFont> AgNotifierFont;

struct FontSpec : public AgNotifier<IFont> {
private:
  IFont defaultFont;
  void initItalic() {
    contents.setItalic();
    defaultFont.setItalic();
  }

public:
  enum Style {
    normal = 0, italic = 1,
    bold = 2, boldItalic = 3,
    underscore = 4, strikeout = 8
  };

  void setStyle(Style style) {
    if (style & italic) {
     	contents.setItalic();
     	defaultFont.setItalic();
    }
    if (style & bold) {
     	contents.setBold();
     	defaultFont.setBold();
    }
    if (style & underscore) {
     	contents.setUnderscore();
     	defaultFont.setUnderscore();
    }
    if (style & strikeout) {
     	contents.setStrikeout();
     	defaultFont.setStrikeout();
    }
  }

  FontSpec(char *name, int size, Style style = normal)
    : AgNotifier<IFont>(IFont(name, size))
    , defaultFont(contents)
  {
    setStyle(style);
  }
  FontSpec(const FontSpec &f)
    : AgNotifier<IFont>(f)
    , defaultFont(f.defaultFont)
  {}
  FontSpec(Style style = normal)
    : AgNotifier<IFont>((IWindow *) 0)
  {
    setStyle(style);
  }
  operator IFont &() { return contents; }

  AgString string();

  IFont &operator = (const IFont &f) {
    contents = f;
    notify();
    return contents;
  }

  int reset();
  AgString description();
  static FontSpec defaultSetting;
  static FontSpec syntaxFile;
  static FontSpec traceFile;
  static FontSpec help;
  static FontSpec helpTitle;
  static FontSpec columnHead;
  static FontSpec dataTable;
  static FontSpec markedToken;
};

struct UndoButton : IPushButton {
  UndoButton(long id, IWindow *owner, IPushButton::Style style = visible)
    : IPushButton(id, owner, owner, IRectangle(), style)
  {
    setText("Undo");
    enableTabStop();
  }
};

struct DefaultButton : IPushButton {
  DefaultButton(long id, IWindow *owner, IPushButton::Style style = visible)
    : IPushButton(id, owner, owner, IRectangle(), style)
  {
    setText("Default");
    enableTabStop();
  }
};

struct OKButton : IPushButton {
  OKButton(long id, IWindow *owner, IPushButton::Style style = visible)
    : IPushButton(id, owner, owner, IRectangle(), style)
  {
    setText("OK");
    enableTabStop();
  }
};

struct CancelButton : IPushButton {
  CancelButton(long id, IWindow *owner, IPushButton::Style style = visible)
    : IPushButton(id, owner, owner, IRectangle(), style)
  {
    setText("Close");
    enableTabStop();
  }
};

struct HelpButton : IPushButton {
  HelpButton(long id, IWindow *owner, IPushButton::Style style = visible)
    : IPushButton(id, owner, owner, IRectangle(), style)
  {
    setText("Help");
    enableTabStop();
  }
};

class ColoredButton
  : public IPushButton
{
private:
  IColor fgColor;
  IColor bgColor;

public:
  ColoredButton(long id, IWindow *owner, ColorSpec *colorPair, char *text);
};


struct ButtonCanvas : ISetCanvas {
  ButtonCanvas(IWindow *owner)
    : ISetCanvas(nextChildId(), owner, owner, IRectangle(),
		   ISetCanvas::horizontalDecks
		 | ISetCanvas::packExpanded
		 | ISetCanvas::rightAlign
		 | ISetCanvas::topAlign
		 | IWindow::clipChildren
		 | IWindow::visible)
  {
    setDeckCount(1);
  }
};

class FontDialog
  : public AgFrame
  , public IPaintHandler
{
public:
  enum { nFontSpecs = 7 };

  struct UndoRecord {
    IPushButton *button; FontSpec *pointer; IFont font;
    int operator < (const UndoRecord &x) const { return pointer < x.pointer; }
  };

  struct SpecRecord { FontSpec *pointer; char *title; };

  struct OptionRecord {
    IStaticText *text; IPushButton *button;
    OptionRecord() : text(0), button(0) {}
    OptionRecord(IStaticText *t, IPushButton *b)
      : text(t), button(b)
    {}
    ~OptionRecord() { delete text; delete button; }
  };

  UndoRecord undoRecord;
  OptionRecord optionRecord[nFontSpecs];
  AgStack<UndoRecord> undoStack;

  static SpecRecord specRecord[nFontSpecs];
  static int idField(AgString name);
  static void initFont(int field, int flags, int size, AgString name);


  IMultiCellCanvas canvas;
    ISetCanvas fontChoices;
    ISetCanvas buttons;
      IPushButton undoButton;
      IPushButton defaultButton;
      IPushButton cancelButton;
      IPushButton helpButton;

  enum {
    undoCommand = nFontSpecs+1,
    defaultCommand,
    cancelCommand,
    helpCommand
  };

public:
  IWindowHandle dialogHandle;
  int fontDialogActive;
  FontDialog();
  ~FontDialog();
  Boolean command(ICommandEvent &);
  Boolean paintWindow(IPaintEvent &);
  //Boolean dispatchHandlerEvent(IEvent &e);
  virtual FontDialog &closeModalDialog();
  virtual FontDialog &mySetFocus();
  //IWindow *activeDialog;
  //virtual Boolean gotFocus(IEvent &) { activeDialog.setFocus(); }
  virtual void popUp();
  virtual void closeFrame();
  static void initFont(int flags, int size);
  static void stackSettings(AgCharStack &stack);
};

class RGBSelector
  : public ISetCanvas
  , public ISpinHandler
  , public IEditHandler
{
  INumericSpinButton redSpinner;
  INumericSpinButton greenSpinner;
  INumericSpinButton blueSpinner;
  IStaticText redText;
  IStaticText greenText;
  IStaticText blueText;
  AgAction changeAction;

public:
  RGBSelector &setChangeAction(AgAction action) {
    changeAction = action;
    return *this;
  }
  RGBSelector(IWindow *owner, IColor color);
  ~RGBSelector();
  IColor value() {
    return IColor(redSpinner.value(),
		  greenSpinner.value(),
		  blueSpinner.value());
  }
  Boolean spinEnded(IControlEvent &) { changeAction.perform(); return false; }
  //Boolean edit(IControlEvent &) { changeAction.perform(); return true; }
  Boolean edit(IControlEvent &);
};

class ColorDialog;

class ColorSelector
  : public AgDialog
  , public ISpinHandler
  , public IFrameHandler
  , public IPaintHandler
{
  enum { okCommand = 1, cancelCommand };
  ColorPair &colorPair;

  ColorDialog *ownerDialog;

  IMultiCellCanvas canvas;
    ISetCanvas workArea;
    		IStaticText sampleText;
    		ISetCanvas selectorCanvas;
      	 //	IStaticText fgText;
      		RGBSelector foregroundSelector;
      	 //	IStaticText bgText;
      		RGBSelector backgroundSelector;
    ButtonCanvas buttonCanvas;
      OKButton     okButton;
      CancelButton cancelButton;

public:
  //ColorSelector(ColorPair &);
  ColorSelector(ColorDialog *, ColorPair &);
  ~ColorSelector();
  Boolean command(ICommandEvent &event);
  Boolean activated(IFrameEvent &event);
  Boolean paintWindow(IPaintEvent &);
  void changeForeground() {
    sampleText.setForegroundColor(foregroundSelector.value()).refresh();
  }
  void changeBackground() {
    sampleText.setBackgroundColor(backgroundSelector.value()).refresh();
  }
};

class ColorDialog
  : public AgFrame
  , public IPaintHandler
{
public:
  enum { nColorSpecs = 12 };

  struct UndoRecord {
    int buttonNumber;
    ColorSpec *pointer;
    ColorPair colorPair;
    int operator < (const UndoRecord &r) const {
      return buttonNumber < r.buttonNumber;
    }
  };

  struct SpecRecord { ColorSpec *pointer; char *title; };

  UndoRecord undoRecord;
  ColoredButton *buttonList[nColorSpecs];
  AgStack<UndoRecord> undoStack;

  static SpecRecord specRecord[nColorSpecs];

  ISetCanvas canvas;
    ISetCanvas colorChoices;
    ButtonCanvas buttons;
      UndoButton undoButton;
      DefaultButton defaultButton;
      CancelButton cancelButton;
      HelpButton helpButton;

  enum {
    undoCommand = nColorSpecs+1,
    defaultCommand,
    cancelCommand,
    helpCommand
  };

public:
  ColorDialog();
  ~ColorDialog();
  Boolean command(ICommandEvent &);
  Boolean paintWindow(IPaintEvent &);
  static void ColorDialog::setColor(ColorPair p);
  static void ColorDialog::stackSettings(AgCharStack &);
  static void ColorDialog::initColor(AgString name, cint p);
};


#endif /* DSPAR_HPP */