view anagram/vaclgui/helpview.hpp @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -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.
 *
 * helpview.hpp
 */

#ifndef HELPVIEW_HPP
#define HELPVIEW_HPP

#include <icanvas.hpp>
#include <iclipbrd.hpp>
#include <icmdevt.hpp>
#include <icmdhdr.hpp>
//#include <icoordsy.hpp>
//#include <idrawcv.hpp>
//#include <iexcbase.hpp>
#include <ifont.hpp>
//#include <igbundle.hpp>
//#include <iglist.hpp>
//#include <igrafctx.hpp>
//#include <igstring.hpp>
#include <ipainhdr.hpp>
#include <ipainevt.hpp>
#include <ikeyhdr.hpp>
#include <ikeyevt.hpp>
#include <imenuevt.hpp>
#include <imenuhdr.hpp>
#include <imoushdr.hpp>
#include <imousevt.hpp>
#include <ipopmenu.hpp>
//#include <irefcnt.hpp>
#include <iscroll.hpp>
#include <iscrlevt.hpp>
#include <iscrlhdr.hpp>
//#include <isizeevt.hpp>
//#include <isizehdr.hpp>
//#include <ititle.hpp>

class AgString; // from agstring.h
#include "agbaltree.h"
#include "cint.h"
#include "dict.h"
#include "digset.hpp"
#include "frame.hpp"
#include "search.h"


#if 0
struct HelpId {
  int index;
  HelpId(int x) : index(x) {}
  HelpId() : index(0) {}
  int operator < (const HelpId id) const {
    int flag = stricmp(dict_str(help_dict, index),
		       dict_str(help_dict, id.index));
    if (flag) {
      return flag < 0;
    }
    return strcmp(dict_str(help_dict, index),
		  dict_str(help_dict, id.index)) < 0;

  }
  operator int () { return index; }
};
#endif

class HelpWord : public DigSetter::Dig {
public:
  enum Style { textStyle, linkStyle, usedStyle, titleStyle };
  HelpWord() {}
  HelpWord(char *, int, cint, Style index = textStyle);
  HelpWord(const HelpWord &);

  //int link;
  AgString linktopic;

  int indent       : 1;
  int forceBreak   : 1;
  int noBreak      : 1;
  int linkTraversed: 1;
  int highlight    : 1;
  int bullet       : 1;
  void moveTo(cint where_) { where = where_; }
  IRectangle rect(DigSetter::Style *style);
  int operator < (const HelpWord &x) const { return this < &x; }
};



class DrawingArea
  : public IStaticText
  , public ICommandHandler
  , public IMenuHandler
  , public IMouseHandler
  , public IPaintHandler
  , public AgHelpHandler
{
public:
  DrawingArea(IWindow *, AgString);
  ~DrawingArea();
  void reset();

  ISize           preferredSize;
  int             nLines;
  int             measure;
  int             spaceRequired;
  IPopUpMenu      popUpMenu;

  DrawingArea &initPopUp();
  DrawingArea &remeasureText();
  AgFrame        *frameWindow;

  static AgBalancedTree<AgString> traversedLinks;

  char *highlightText;
  int  nHighlight;
  DrawingArea &refreshWords(char *p, int n);
  DrawingArea &copyTo(IClipboard &c);

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

protected:

  Boolean DrawingArea::paintWindow(IPaintEvent &event);
  Boolean command(ICommandEvent &event);
  ISize calcMinimumSize() const;

  Boolean mouseClicked(IMouseClickEvent &event);
  Boolean mouseMoved(IMouseEvent &event);
  Boolean makePopUpMenu(IMenuEvent &event);
  Boolean showHelp(IEvent &event);

  DrawingArea &measureText();
  AgString getHelpText(const char *topic);
  AgArray<AgString> findLinks(AgString msg);
  static AgArray<AgString> sortLinks(AgArray<AgString> links);

  virtual IFont font() const {
    return FontSpec::help;
  }

  int lineHeight() {
    IFont &font = FontSpec::help;
    return font.externalLeading() + font.maxSize().height();
  }
  int maxCharWidth() {
    IFont &font = FontSpec::help;
    return font.maxSize().width();
  }
  int avgCharWidth() {
    IFont &font = FontSpec::help;
    return font.avgCharWidth();
  }
  int maxDescender() {
    IFont &font = FontSpec::help;
    return font.maxDescender();
  }

  DrawingArea &refreshLinks();
  void refreshAllLinks();

  AgClassAction<DrawingArea> refreshAction;

public:
  AgString                helpText;
  AgString                topic;
  int                     myTextLength;

  AgStack<HelpWord> word;
  int nWords;
  static DigSetter::Style displayStyle[4];
  DigSetter setter;
  int painting;

private:
  int fingerCursorSet;
  IPointerHandle fingerCursor;

  IFont windowFont;
  int             longestLine;
  int             margin;
  int             paraIndent;
  int             paraLeading;
  int             helpShowing;

  AgArray<AgString> links;
  AgArray<AgString> sortedLinks;
  AgArray<int> linkedWords;
  //static AgDictionary<DrawingArea *> activeViews;
  static AgBalancedTree<DrawingArea *> activeViews;

  int charWidth[256];
};

class AgHelpView
  : public ICanvas
  , public IKeyboardHandler
  , public IResizeHandler
  , public IScrollHandler
{
public:
  static const int defaultWindowHeight;

  // Constructor
  AgHelpView(IWindow *, AgString);

  // Destructor
  ~AgHelpView();

  ISize   suggestSize();

  AgHelpView &layout();
  AgHelpView &doLayout();
  AgHelpView &repositionWindow();

  DrawingArea      dataArea;

  SearchProcess searchProcess;

  virtual Boolean  findNext(AgString);
  virtual Boolean  findPrev(AgString);
  AgHelpView &positionWords(char *p, int n);
  AgHelpView &copyTo(IClipboard &c) {
    dataArea.copyTo(c);
    return *this;
  }

protected:

  // Layout functions

  int lineHeight() {
    IFont &font = FontSpec::help;
    return font.externalLeading() + font.maxSize().height();
  }
  int maxCharWidth() {
    IFont &font = FontSpec::help;
    return font.maxSize().width();
  }
  int avgCharWidth() {
    IFont &font = FontSpec::help;
    return font.avgCharWidth();
  }
  int maxDescender() {
    IFont &font = FontSpec::help;
    return font.maxDescender();
  }

  Boolean windowResize(IResizeEvent &event);
  ISize calcMinimumSize() const;

  // Handler functions


  // Keyboard handler
  Boolean virtualKeyPress(IKeyboardEvent &);

  // Menu handler


  // Scroll handler

  Boolean lineDown(IScrollEvent &);
  Boolean lineUp(IScrollEvent &);
  Boolean pageDown(IScrollEvent &);
  Boolean pageUp(IScrollEvent &);
  Boolean scrollBoxTrack(IScrollEvent &);

private:

public:
  // child windows
  IScrollBar       verticalScrollBar;

  // window parameters
  int windowId;
  //IWindow *ownerWindow;
  int                     highlightIndex;

  //layout state
  Boolean         vsbShowing;
  int layoutActive;

  AgNotificationAction<AgHelpView> colorChange;
  void onColorChange() { refresh(); }
  AgNotificationAction<AgHelpView> fontChange;
  void onFontChange();
};

class AgHelpWindow
  : public AgFrame
{
public:
  AgHelpWindow(AgString);
  ~AgHelpWindow();

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

  static Boolean AgHelpWindow::showHelp(AgString topic);
  static Boolean AgHelpWindow::showHelpCentered(AgString topic);

//private:
  AgString copyTitleText;

  // Child Windows
  AgHelpView      helpView;

public:
  AgHelpWindow &setFocus() {
    helpView.setFocus();
    return *this;
  }
  virtual Boolean findNext(AgString s) {
    return helpView.findNext(s);
  }
  virtual Boolean findPrev(AgString s) {
    return helpView.findPrev(s);
  }
  AgHelpWindow &copyTo(IClipboard &c) {
    helpView.copyTo(c);
    return *this;
  }
  AgString copyTitle() { return copyTitleText.pointer(); };
};


#endif /* HELPVIEW_HPP */