comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * agview.hpp
7 */
8
9 #ifndef AGVIEW_HPP
10 #define AGVIEW_HPP
11
12 #include <icanvas.hpp>
13 //#include <ictlevt.hpp>
14 //#include <iexcbase.hpp>
15 //#include <ifocshdr.hpp>
16 #include <ifont.hpp>
17 #include <ikeyevt.hpp>
18 #include <ikeyhdr.hpp>
19 #include <imousevt.hpp>
20 #include <imoushdr.hpp>
21 #include <imphdr.hpp>
22 #include <ipainevt.hpp>
23 #include <ipainhdr.hpp>
24 //#include <irefcnt.hpp>
25 #include <iscrlevt.hpp>
26 #include <iscrlhdr.hpp>
27 #include <iscroll.hpp>
28 //#include <isizeevt.hpp>
29 #include <isizehdr.hpp>
30 #include <istattxt.hpp>
31 #include <itimer.hpp>
32 //#include <ititle.hpp>
33 //#include <windows.h>
34
35 #include "agnotify.h"
36 #include "cint.h"
37 #include "frame.hpp"
38 #include "base.h"
39
40
41 class ColorSpec;
42
43 class AgFocusHandler : public IHandler {
44 virtual Boolean gotFocus(IEvent &) { return false; }
45 virtual Boolean lostFocus(IEvent &) { return false; }
46 virtual Boolean dispatchHandlerEvent(IEvent &);
47 };
48
49 class AgStaticText
50 : public IStaticText
51 {
52 public:
53 AgStaticText(IWindow *owner)
54 : IStaticText(nextChildId(), owner, owner, IRectangle(),
55 classDefaultStyle | tabStop)
56 {}
57 AgStaticText(int id, IWindow *a, IWindow *b)
58 : IStaticText(id, a, b, IRectangle(),
59 classDefaultStyle | tabStop)
60 {}
61 AgStaticText &scrollWindow(IPoint distance);
62 };
63
64 class AgColumnHead
65 : public IStaticText
66 , public IPaintHandler
67 {
68 private:
69 int nCols;
70 int *tabs;
71 int margin;
72 //int yBias;
73
74 public:
75 AgString title;
76
77 AgColumnHead(int id, IWindow *parent);
78 ~AgColumnHead();
79 void setTitles(int, AgString);
80 void setMargin(int);
81 void setPos(int);
82 void setTabs(int *);
83 Boolean paintWindow(IPaintEvent &event);
84 int xPos;
85 ColorSpec *color;
86 AgNotificationAction<AgColumnHead> dataColorChange;
87 void onColorChange() {refresh();}
88 };
89
90 class AgView
91 : public ICanvas
92 , public AgFocusHandler
93 , public IKeyboardHandler
94 , public IMousePointerHandler
95 , public IPaintHandler
96 , public IResizeHandler
97 , public IScrollHandler
98 {
99 public:
100
101 static const int defaultWindowHeight;
102
103 class MouseDragTimer : public ITimerFn {
104 private:
105 AgView *window;
106 int mouseLine;
107 int topLine;
108
109 public:
110 MouseDragTimer(AgView *, int, int);
111 void timerExpired(unsigned long timerId);
112 };
113
114 // Constructor
115 AgView(IWindow *);
116
117 // Destructor
118 ~AgView();
119
120 AgView &enableCursor(int flag = true);
121 AgView &enableCursorBar(int flag = true);
122 virtual Boolean gotFocus(IEvent &);
123 virtual Boolean lostFocus(IEvent &);
124 void mouseDragTimerInterrupt(int &topLine, int mouseLine);
125
126 virtual ISize suggestSize();
127 AgColumnHead columnHeadTitle;
128
129 public:
130 // Layout functions
131 virtual ICanvas &layout();
132 virtual ICanvas &setLayoutDistorted(unsigned long, unsigned long);
133 virtual AgView &doLayout();
134 virtual Boolean windowResize(IResizeEvent &);
135 //virtual AgView &repositionWindow();
136 int lineHeight() {
137 return font().externalLeading() + font().maxSize().height();
138 }
139 int maxCharWidth() { return font().maxSize().width(); }
140 int avgCharWidth() { return font().avgCharWidth(); }
141 int maxDescender() { return font().maxDescender(); }
142 AgView &repaintLine(int);
143 virtual int findMaxWidth(void);
144
145 // Handler functions
146
147 // Keyboard handler
148 Boolean virtualKeyPress(IKeyboardEvent &);
149
150 // Mouse handler
151 virtual Boolean mouseClicked(IMouseClickEvent &event);
152 virtual Boolean mouseMoved(IMouseEvent &event);
153 void dragMouse(int topLine, int mouseLine);
154
155 Boolean mouseDown;
156 ITimer mouseTimer;
157 int mouseDownCursorLine;
158
159 // Paint handler
160 virtual Boolean paintWindow(IPaintEvent &);
161
162 // Scroll handler
163 virtual Boolean lineDown(IScrollEvent &);
164 virtual Boolean lineLeft(IScrollEvent &);
165 virtual Boolean lineRight(IScrollEvent &);
166 virtual Boolean lineUp(IScrollEvent &);
167 virtual Boolean pageDown(IScrollEvent &);
168 virtual Boolean pageLeft(IScrollEvent &);
169 virtual Boolean pageRight(IScrollEvent &);
170 virtual Boolean pageUp(IScrollEvent &);
171 virtual Boolean scrollBoxTrack(IScrollEvent &);
172 virtual Boolean scrollBoxTrackEnd(IScrollEvent &event) {
173 return scrollBoxTrack(event);
174 }
175
176 // Virtual functions: Access to data
177 virtual AgString getLine(unsigned) { return AgString(); }
178 virtual unsigned nLines() { return 0; }
179 virtual unsigned nColumns() { return 1; }
180 virtual AgString headTitle() { return AgString(); }
181 virtual AgString columnTitleText() { return AgString(); }
182 virtual AgString footTitle() { return AgString(); }
183
184 //virtual const IColor getColor(ColorCode code) = 0;
185
186 //Notification overridables
187
188 AgAction enterAction;
189 void setEnterAction(AgAction action) { enterAction = action; }
190 virtual void onEnter() { enterAction.performDeferred(); }
191
192 AgAction selectAction;
193 void setSelectAction(AgAction action) { selectAction = action; }
194 virtual void onSelect() { selectAction.performDeferred(); }
195
196 AgView &AgView::updateCursor(int);
197 AgView &AgView::updateCursor();
198 AgView &AgView::reposition();
199 AgView &AgView::repaintCursor(int line);
200
201 void checkFocus(void);
202
203 cint cursorLocation;
204 cint pixelCursor;
205
206 AgView &cursorOn();
207 AgView &cursorOff();
208 virtual AgView &setCursorLocation(cint loc);
209 virtual AgView &scrollTo(cint loc);
210 virtual cint getCursorLocation() { return cursorLocation; }
211
212 AgView &hideCursor();
213 AgView &showCursor();
214 AgView &setCursorPos(cint);
215
216 int cursorHideCount;
217
218 int layoutActive;
219
220 virtual Boolean findNext(AgString) { return false; }
221 virtual Boolean findPrev(AgString) { return false; }
222
223 protected:
224 // child windows
225 ICanvas dataHole;
226 IScrollBar horizontalScrollBar;
227 IScrollBar verticalScrollBar;
228
229 //ColorUsage dataUsage;
230 //ColorUsage activeCursorUsage;
231 //ColorUsage inactiveCursorUsage;
232
233 ColorSpec *color;
234 ColorSpec *cursorColor;
235
236 AgNotificationAction<AgView> dataColorChange;
237 void onColorChange() { refresh(); }
238
239 public:
240 AgStaticText dataArea;
241
242 // window parameters
243 int windowId;
244 IWindow *ownerWindow;
245 AgFrame *frameWindow;
246 AgView &setFrame(AgFrame *f) { frameWindow = f; return *this; }
247
248 int *tabArray;
249
250 // layout state
251 Boolean vsbShowing;
252 Boolean hsbShowing;
253 int columnHeadsPresent;
254 int columnHeadWidth;
255 int tableWidth;
256 int tableHeight;
257
258 int cursorEnabled;
259 int cursorLineHighlight;
260 int retainCursor;
261 int prevHorizontal;
262 int prevVertical;
263
264 // window state
265 int cursorLine;
266 int rightButtonDown;
267
268 AgView &setFocus() {
269 dataArea.setFocus();
270 return *this;
271 }
272 virtual int charPosition(int xPos, AgString line);
273 virtual int xPosition(int charPos, AgString line);
274 int charWidth[256];
275 };
276
277
278 extern int focusWindowId;
279
280
281 #endif /* AGVIEW_HPP */