view anagram/vaclgui/gtview.hpp @ 12:aab9ff6af791

Strengthen the build hack for non-DOS targets.
author David A. Holland
date Tue, 31 May 2022 00:58:42 -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.
 *
 * gtview.hpp
 */

#ifndef GTVIEW_HPP
#define GTVIEW_HPP

#include <icombobx.hpp>
//#include <iedithdr.hpp>
#include <ikeyevt.hpp>
#include <ikeyhdr.hpp>
#include <imcelcv.hpp>
#include <imousevt.hpp>
#include <imoushdr.hpp>
#include <ipainevt.hpp>
#include <ipainhdr.hpp>
#include <isizehdr.hpp>
#include <islhdr.hpp>
#include <isplitcv.hpp>
#include <istattxt.hpp>

//#include "agview.hpp"
#include "brt.h"
#include "conflicttrc.h"
#include "dview.hpp"
#include "dvplug.hpp"
#include "frame.hpp"
#include "ftpar.h"
#include "ftpardc.h"
#include "toolbar.hpp"

class trace_window_dc; // from tracedc.h


class GTWindow; // below

class GTView
  : public ICanvas
  , public AgFocusHandler
  , public IFocusHandler
  , public IMouseHandler
  , public IPaintHandler
{
public:
  GTView(GTWindow *owner_, DcRef<FtParserDc>);
  ~GTView();

  GTView &refreshRules(int);
  DcRef<FtParserDc> parserDc;
  AgDataViewPlug *stackViewData;
  FtParser &parser;

  ISplitCanvas mainSplitter;
    ISplitCanvas tracePanels;
      IMultiCellCanvas leftPanel;
        AgDataView stackView;
        IStaticText stackTitle;
      IMultiCellCanvas rightPanel;
        AgDataView tokenListView;
        IStaticText tokenListTitle;
    ISplitCanvas bottomPanel;
      AgDataView reductionChoiceView;
        DcRef<FtParserReductionDc> reductionMenu;
      AgDataView ruleView;
        AgDataViewPlug *ruleConnector;

  tsd *itemStack;
  DcRef<rule_stack_dc> ruleControl;


  virtual Boolean gotFocus(IEvent &);
  virtual Boolean lostFocus(IEvent &);
  virtual Boolean gotFocus(IControlEvent &);
  virtual Boolean lostFocus(IControlEvent &);
  Boolean mouseClicked(IMouseClickEvent &event);
  Boolean paintWindow(IPaintEvent &event);
  //GTView &completeReduction();
  //GTView &setFocus();

  int focusControl;
  int activePanel;

  enum ButtonState { buttonIdle, buttonDown, waitingForClick };
  ButtonState leftButtonState;

  int followUpPending;
  void followUpFocusMsg();

private:
  AgNotificationAction<GTView> dataColorChange;
  void onColorChange() { stackTitle.refresh(); tokenListTitle.refresh(); }
  AgNotificationAction<GTView> fontChange;
  void onFontChange() {
    stackTitle.setFont(FontSpec::columnHead).refresh();
    tokenListTitle.setFont(FontSpec::columnHead).refresh();
  }
  GTWindow *frame;
  //HelpDemon stackViewHelp;
  //HelpDemon tokenViewHelp;
};

class GTWindow
  : public AgFrame
  , public IShowListHandler
/*, public IKeyboardHandler - compiler complains because AgFrame has one */
  , public IMouseHandler
{
public:
  class ComboBox : public IComboBox {
  public:
    ComboBox(IWindow *owner, char *text)
      : IComboBox(nextChildId(), owner, owner, IRectangle(),
		  autoScroll |
		  dropDownType | horizontalScroll)
    {
      //LOGSECTION("GTWindow::ComboBox::ComboBox");
      IFont f = font();
      ISize minimum(f.textWidth(text),f.maxCharHeight() );
      //LOGV(minimum.asString());
      setMinimumSize(minimum).show();
      addAsLast("");
    }

    void saveText();

    AgAction enterAction;
    ComboBox &setEnterAction(AgAction action) {
      enterAction = action;
      return *this;
    }
    virtual void onEnter() {
      enterAction.performDeferred();
    }

    AgAction selectAction;
    ComboBox &setSelectAction(AgAction action) {
      selectAction = action;
      return *this;
    }
    virtual void onSelect() {
      selectAction.performDeferred();
    }

    Boolean enter(IControlEvent &) { onEnter(); return true; }
    Boolean select(IControlEvent &) { onSelect(); return true; }

    // otherwise the compiler complains this is hidden
    virtual IBaseComboBox &select(unsigned long a, IBase::Boolean b) {
      return IBaseComboBox::select(a,b);
    }
  };

  FtParser parser;
  DcRef<FtParserDc> parserDc;
  GTWindow(trace_window_dc *);
  GTWindow(tsd *initialStates, 
	   AgString headTitle, AgString footTitle = AgString());
  ~GTWindow();
  void init();
  //void stackEnter();
  void stackSelect();
  void ruleSelect();
  void tokenEnter();
  void acceptToken();
  void tokenProceed();
  void tokenSelect();
  void setUpViews();
  virtual AgString copyTitle();
  virtual GTWindow &copyTo(IClipboard &c);

  // otherwise the compiler complains this is hidden
  virtual int showHelp(IEvent &e) { return AgFrame::showHelp(e); }

  Boolean windowResize(IResizeEvent &event);
  //Boolean command(ICommandEvent &event);
  Boolean listShown(IControlEvent &event);
  Boolean virtualKeyPress(IKeyboardEvent &event);
  Boolean characterKeyPress(IKeyboardEvent &event);
  Boolean mouseClicked(IMouseClickEvent &event);

  GTWindow &showReductionSelection();
  void reductionChoiceEnter();
  void reductionChoiceSelect();

  //AgInfoField statusField;
  ToolBar toolBar;
  ToolBar containerBar;
  IStaticText statusField;
  HelpDemon statusFieldHelp;
  GTWindow &setStatusField();
  void resetParser();

  void comboBoxEnter();
  void comboBoxSelect();
  void comboBoxProceed();
  void comboBoxStep();
  void doStep();
  void proceed();
  void showHelp();

  void synchRules(unsigned sn, unsigned token);
  void synchTokenList(unsigned sn, unsigned tn);
  void setLookaheadToken(unsigned tn);
  void onDeactivate();

  ComboBox comboBox;
  //ControlHelpDemon comboBoxHelp;
  //AgToolControl comboBoxTool;



  GTView canvas;
  DcRef<TokenMenuDc> tokenList;

  ToolBar buttonGroup;
  ToolButton proceedButton;
  ToolButton stepButton;
  ToolButton resetButton;
  ToolButton helpButton;

  static char *processStateText[];
  int comboBoxActive;
  int comboBoxListShowing;
  int ruleSelectActive;

public:
  int listViewLine;
  int stackViewLine;
  int ruleViewLine;
  int reductionChoiceLine;
  GTWindow &setFocus();

public:
  virtual Boolean  findNext(AgString s);
  virtual Boolean  findPrev(AgString s);
  unsigned selectedToken;

  void setRuleViewCursor();

  class TabControl {
  public:
    int enabled;
    char *helpTopic;
    AgAction action;
    IWindow *window;

    TabControl() {}
    TabControl(IWindow *window_,
	       char *helpTopic_,
	       AgAction action_ = AgAction())
      : enabled(1)
      , helpTopic(helpTopic_)
      , action(action_)
      , window(window_)
      {}
    TabControl(const TabControl &x)
      : enabled(x.enabled)
      , helpTopic(x.helpTopic)
      , action(x.action)
      , window(x.window)
      {}
  };
  enum {
    stackTab,
    tokenTab,
    choiceTab,
    ruleTab,
    comboTab,
    proceedTab,
    stepTab,
    resetTab,
    helpTab,
    nTabs
  };
  TabControl tabControl[nTabs];
};


#endif /* GTVIEW_HPP */