diff anagram/vaclgui/agview.hpp @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/anagram/vaclgui/agview.hpp	Sat Dec 22 17:52:45 2007 -0500
@@ -0,0 +1,281 @@
+/*
+ * AnaGram, A System for Syntax Directed Programming
+ * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
+ * See the file COPYING for license and usage terms.
+ *
+ * agview.hpp
+ */
+
+#ifndef AGVIEW_HPP
+#define AGVIEW_HPP
+
+#include <icanvas.hpp>
+//#include <ictlevt.hpp>
+//#include <iexcbase.hpp>
+//#include <ifocshdr.hpp>
+#include <ifont.hpp>
+#include <ikeyevt.hpp>
+#include <ikeyhdr.hpp>
+#include <imousevt.hpp>
+#include <imoushdr.hpp>
+#include <imphdr.hpp>
+#include <ipainevt.hpp>
+#include <ipainhdr.hpp>
+//#include <irefcnt.hpp>
+#include <iscrlevt.hpp>
+#include <iscrlhdr.hpp>
+#include <iscroll.hpp>
+//#include <isizeevt.hpp>
+#include <isizehdr.hpp>
+#include <istattxt.hpp>
+#include <itimer.hpp>
+//#include <ititle.hpp>
+//#include <windows.h>
+
+#include "agnotify.h"
+#include "cint.h"
+#include "frame.hpp"
+#include "base.h"
+
+
+class ColorSpec;
+
+class AgFocusHandler : public IHandler {
+  virtual Boolean gotFocus(IEvent &) { return false; }
+  virtual Boolean lostFocus(IEvent &) { return false; }
+  virtual Boolean dispatchHandlerEvent(IEvent &);
+};
+
+class AgStaticText
+  : public IStaticText
+{
+public:
+  AgStaticText(IWindow *owner)
+    : IStaticText(nextChildId(), owner, owner, IRectangle(), 
+		  classDefaultStyle | tabStop)
+  {}
+  AgStaticText(int id, IWindow *a, IWindow *b)
+    : IStaticText(id, a, b, IRectangle(), 
+		  classDefaultStyle | tabStop)
+  {}
+  AgStaticText &scrollWindow(IPoint distance);
+};
+
+class AgColumnHead
+  : public IStaticText
+  , public IPaintHandler
+{
+private:
+  int nCols;
+  int *tabs;
+  int margin;
+  //int yBias;
+
+public:
+  AgString title;
+
+  AgColumnHead(int id, IWindow *parent);
+  ~AgColumnHead();
+  void setTitles(int, AgString);
+  void setMargin(int);
+  void setPos(int);
+  void setTabs(int *);
+  Boolean paintWindow(IPaintEvent &event);
+  int xPos;
+  ColorSpec *color;
+  AgNotificationAction<AgColumnHead> dataColorChange;
+  void onColorChange() {refresh();}
+};
+
+class AgView
+  : public ICanvas
+  , public AgFocusHandler
+  , public IKeyboardHandler
+  , public IMousePointerHandler
+  , public IPaintHandler
+  , public IResizeHandler
+  , public IScrollHandler
+{
+public:
+
+  static const int defaultWindowHeight;
+
+  class MouseDragTimer : public ITimerFn {
+  private:
+    AgView *window;
+    int mouseLine;
+    int topLine;
+
+  public:
+    MouseDragTimer(AgView *, int, int);
+    void timerExpired(unsigned long timerId);
+  };
+
+  // Constructor
+  AgView(IWindow *);
+
+  // Destructor
+  ~AgView();
+
+  AgView &enableCursor(int flag = true);
+  AgView &enableCursorBar(int flag = true);
+  virtual Boolean gotFocus(IEvent &);
+  virtual Boolean lostFocus(IEvent &);
+  void    mouseDragTimerInterrupt(int &topLine, int mouseLine);
+
+  virtual ISize    suggestSize();
+  AgColumnHead       columnHeadTitle;
+
+public:
+  // Layout functions
+  virtual ICanvas &layout();
+  virtual ICanvas &setLayoutDistorted(unsigned long, unsigned long);
+  virtual AgView &doLayout();
+  virtual Boolean windowResize(IResizeEvent &);
+  //virtual AgView &repositionWindow();
+  int lineHeight() {
+    return font().externalLeading() + font().maxSize().height();
+  }
+  int maxCharWidth() { return font().maxSize().width(); }
+  int avgCharWidth() { return font().avgCharWidth(); }
+  int maxDescender() { return font().maxDescender(); }
+  AgView &repaintLine(int);
+  virtual int findMaxWidth(void);
+
+  // Handler functions
+
+  // Keyboard handler
+  Boolean virtualKeyPress(IKeyboardEvent &);
+
+  // Mouse handler
+  virtual Boolean mouseClicked(IMouseClickEvent &event);
+  virtual Boolean mouseMoved(IMouseEvent &event);
+  void    dragMouse(int topLine, int mouseLine);
+
+  Boolean          mouseDown;
+  ITimer           mouseTimer;
+  int              mouseDownCursorLine;
+
+  // Paint handler
+  virtual Boolean paintWindow(IPaintEvent &);
+
+  // Scroll handler
+  virtual Boolean lineDown(IScrollEvent &);
+  virtual Boolean lineLeft(IScrollEvent &);
+  virtual Boolean lineRight(IScrollEvent &);
+  virtual Boolean lineUp(IScrollEvent &);
+  virtual Boolean pageDown(IScrollEvent &);
+  virtual Boolean pageLeft(IScrollEvent &);
+  virtual Boolean pageRight(IScrollEvent &);
+  virtual Boolean pageUp(IScrollEvent &);
+  virtual Boolean scrollBoxTrack(IScrollEvent &);
+  virtual Boolean scrollBoxTrackEnd(IScrollEvent &event) {
+    return scrollBoxTrack(event);
+  }
+
+  // Virtual functions: Access to data
+  virtual AgString getLine(unsigned) { return AgString(); }
+  virtual unsigned nLines() { return 0; }
+  virtual unsigned nColumns() { return 1; }
+  virtual AgString headTitle() { return AgString(); }
+  virtual AgString columnTitleText() { return AgString(); }
+  virtual AgString footTitle() { return AgString(); }
+
+  //virtual const IColor getColor(ColorCode code) = 0;
+
+  //Notification overridables
+
+  AgAction enterAction;
+  void setEnterAction(AgAction action) { enterAction = action; }
+  virtual void onEnter() { enterAction.performDeferred(); }
+
+  AgAction selectAction;
+  void setSelectAction(AgAction action) { selectAction = action; }
+  virtual void onSelect() { selectAction.performDeferred(); }
+
+  AgView &AgView::updateCursor(int);
+  AgView &AgView::updateCursor();
+  AgView &AgView::reposition();
+  AgView &AgView::repaintCursor(int line);
+
+  void checkFocus(void);
+
+  cint            cursorLocation;
+  cint            pixelCursor;
+
+  AgView &cursorOn();
+  AgView &cursorOff();
+  virtual AgView &setCursorLocation(cint loc);
+  virtual AgView &scrollTo(cint loc);
+  virtual cint getCursorLocation() { return cursorLocation; }
+
+  AgView &hideCursor();
+  AgView &showCursor();
+  AgView &setCursorPos(cint);
+
+  int cursorHideCount;
+
+  int layoutActive;
+
+  virtual Boolean  findNext(AgString) { return false; }
+  virtual Boolean  findPrev(AgString) { return false; }
+
+protected:
+  // child windows
+  ICanvas          dataHole;
+  IScrollBar       horizontalScrollBar;
+  IScrollBar       verticalScrollBar;
+
+  //ColorUsage dataUsage;
+  //ColorUsage activeCursorUsage;
+  //ColorUsage inactiveCursorUsage;
+
+  ColorSpec *color;
+  ColorSpec *cursorColor;
+
+  AgNotificationAction<AgView> dataColorChange;
+  void onColorChange() { refresh(); }
+
+public:
+  AgStaticText      dataArea;
+
+  // window parameters
+  int windowId;
+  IWindow *ownerWindow;
+  AgFrame *frameWindow;
+  AgView &setFrame(AgFrame *f) { frameWindow = f; return *this; }
+
+  int             *tabArray;
+
+  // layout state
+  Boolean         vsbShowing;
+  Boolean         hsbShowing;
+  int             columnHeadsPresent;
+  int             columnHeadWidth;
+  int             tableWidth;
+  int             tableHeight;
+
+  int             cursorEnabled;
+  int             cursorLineHighlight;
+  int             retainCursor;
+  int             prevHorizontal;
+  int             prevVertical;
+
+  // window state
+  int             cursorLine;
+  int             rightButtonDown;
+
+  AgView &setFocus() {
+    dataArea.setFocus();
+    return *this;
+  }
+  virtual int charPosition(int xPos, AgString line);
+  virtual int xPosition(int charPos, AgString line);
+  int charWidth[256];
+};
+
+
+extern int focusWindowId;
+
+
+#endif /* AGVIEW_HPP */