-
Notifications
You must be signed in to change notification settings - Fork 3
/
codePreviewForm.e
217 lines (187 loc) · 6.28 KB
/
codePreviewForm.e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
OPT MODULE, OSVERSION=37
MODULE 'reaction/reaction_macros',
'window','classes/window',
'gadgets/layout','layout',
'reaction/reaction_lib',
'images/bevel',
'gadgets/textEditor','texteditor',
'*textfield',
'gadgets/scroller','scroller',
'graphics/gfxbase',
'images/label','label',
'amigalib/boopsi',
'intuition/intuition',
'intuition/imageclass',
'intuition/gadgetclass',
'intuition/cghooks',
'intuition/icclass'
MODULE '*reactionForm','*stringStreamer'
EXPORT DEF texteditorbase
CONST TEXTFIELD_TEXT=$84000001
CONST TEXTFIELD_TEXTFONT=$84000003
CONST TEXTFIELD_BORDER_BEVEL=1
CONST TEXTFIELD_BORDER=$8400000C
CONST TEXTFIELD_SIZE=$84000007
CONST TEXTFIELD_READONLY=$8400001F
CONST TEXTFIELD_TOP=$84000005
CONST TEXTFIELD_LINES=$84000009
CONST TEXTFIELD_VISIBLE=$84000008
CONST TEXTFIELD_INSERTTEXT=$84000002
EXPORT ENUM PREVIEWGAD_TEXT, PREVIEWGAD_SCROLL
CONST NUM_PREVIEW_GADS=PREVIEWGAD_SCROLL+1
EXPORT OBJECT codePreviewForm OF reactionForm
ENDOBJECT
PROC createTextFieldGad() OF codePreviewForm
DEF gfxb:PTR TO gfxbase
DEF res
gfxb:=gfxbase
res:=NewObjectA( TextField_GetClass(), NIL,[
GA_ID, PREVIEWGAD_TEXT,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
TEXTFIELD_TEXTFONT, gfxb.defaultfont,
TEXTFIELD_READONLY, TRUE,
TEXTFIELD_BORDER, TEXTFIELD_BORDER_BEVEL,
TAG_END])
ENDPROC res
EXPORT PROC create() OF codePreviewForm
DEF gads:PTR TO LONG
DEF tempbase=0,map
NEW gads[NUM_PREVIEW_GADS]
self.gadgetList:=gads
NEW gads[NUM_PREVIEW_GADS]
IF texteditorbase
tempbase:=textfieldbase
textfieldbase:=texteditorbase
self.gadgetList[ PREVIEWGAD_TEXT ]:=NewObjectA( TextEditor_GetClass(), NIL,[
GA_ID, PREVIEWGAD_TEXT,
GA_TEXTEDITOR_WRAPBORDER,-1,
GA_TEXTEDITOR_FIXEDFONT,TRUE,
GA_TEXTEDITOR_HORIZONTALSCROLL, TRUE,
GA_TEXTEDITOR_SHOWLINENUMBERS, TRUE,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, TRUE,
TAG_END])
ELSE
self.gadgetList[ PREVIEWGAD_TEXT ]:=self.createTextFieldGad()
ENDIF
self.gadgetActions:=gads
self.windowObj:=WindowObject,
WA_TITLE, 'Code Preview',
WA_LEFT, 0,
WA_TOP, 20,
WA_HEIGHT, 100,
WA_WIDTH, 200,
WA_MINWIDTH, 150,
WA_MAXWIDTH, 8192,
WA_MINHEIGHT, 80,
WA_MAXHEIGHT, 8192,
WA_ACTIVATE, FALSE,
WA_PUBSCREEN, 0,
->WA_CustomScreen, gScreen,
->WINDOW_AppPort, gApp_port,
WA_CLOSEGADGET, TRUE,
WA_DEPTHGADGET, TRUE,
WA_SIZEGADGET, TRUE,
WA_DRAGBAR, TRUE,
WA_NOCAREREFRESH, TRUE,
WA_IDCMP,IDCMP_GADGETDOWN OR IDCMP_GADGETUP OR IDCMP_CLOSEWINDOW OR IDCMP_NEWSIZE,
WINDOW_PARENTGROUP, HLayoutObject,
LAYOUT_SPACEOUTER, TRUE,
LAYOUT_DEFERLAYOUT, TRUE,
LAYOUT_ADDCHILD, self.gadgetList[ PREVIEWGAD_TEXT ],
LAYOUT_ADDCHILD, self.gadgetList[ PREVIEWGAD_SCROLL ]:=NewObjectA(Scroller_GetClass(),NIL,[
GA_ID, PREVIEWGAD_SCROLL,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
SCROLLER_ARROWS, TRUE,
SCROLLER_ORIENTATION, SORIENT_VERT,
TAG_END]),
LayoutEnd,
WindowEnd
IF texteditorbase
map:=[GA_TEXTEDITOR_PROP_FIRST, SCROLLER_TOP,
GA_TEXTEDITOR_PROP_ENTRIES, SCROLLER_TOTAL,
GA_TEXTEDITOR_PROP_VISIBLE, SCROLLER_VISIBLE,
TAG_DONE]
ELSE
map:=[TEXTFIELD_TOP, SCROLLER_TOP,
TEXTFIELD_LINES, SCROLLER_TOTAL,
TEXTFIELD_VISIBLE, SCROLLER_VISIBLE,
TAG_DONE]
ENDIF
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],0,0,[ICA_MAP,map,ICA_TARGET,self.gadgetList[ PREVIEWGAD_SCROLL ],0])
IF texteditorbase
map:=[
SCROLLER_TOP, GA_TEXTEDITOR_PROP_FIRST,
SCROLLER_TOTAL, GA_TEXTEDITOR_PROP_ENTRIES,
SCROLLER_VISIBLE, GA_TEXTEDITOR_PROP_VISIBLE,
TAG_DONE]
ELSE
map:=[
SCROLLER_TOP, TEXTFIELD_TOP,
SCROLLER_TOTAL, TEXTFIELD_LINES,
SCROLLER_VISIBLE, TEXTFIELD_VISIBLE,
TAG_DONE]
ENDIF
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_SCROLL ],0,0,[ICA_MAP,map,ICA_TARGET,self.gadgetList[ PREVIEWGAD_TEXT ],0])
IF tempbase THEN textfieldbase:=tempbase
ENDPROC
PROC end() OF codePreviewForm
self.close()
END self.gadgetList[NUM_PREVIEW_GADS]
END self.gadgetActions[NUM_PREVIEW_GADS]
DisposeObject(self.windowObj)
ENDPROC
EXPORT PROC showCode(strStream:PTR TO stringStreamer) OF codePreviewForm
DEF str[201]:ARRAY OF CHAR
DEF win,top
DEF newgad,tempdata,size
strStream.reset()
win:=Gets(self.windowObj,WINDOW_WINDOW)
top:=Gets(self.gadgetList[ PREVIEWGAD_SCROLL ],SCROLLER_TOP)
IF texteditorbase
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_CLEARTEXT, 0]:gp_texteditor_cleartext)
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,1,TAG_END])
ELSE
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_TEXT,'',0])
newgad:=self.createTextFieldGad()
ENDIF
WHILE strStream.readLine(str)<>-1
str[StrLen(str)+1]:=0
str[StrLen(str)]:="\n"
IF texteditorbase
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_INSERTTEXT, 0, str, GV_TEXTEDITOR_INSERTTEXT_BOTTOM]:gp_texteditor_inserttext)
ELSE
SetGadgetAttrsA(newgad,0,0,[TEXTFIELD_INSERTTEXT,str,0])
ENDIF
ENDWHILE
IF texteditorbase
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,FALSE,TAG_END])
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_PROP_FIRST,top,TAG_END])
ELSE
size:=Gets(newgad,TEXTFIELD_SIZE)
tempdata:=New(size)
IF tempdata
CopyMem(Gets(newgad,TEXTFIELD_TEXT),tempdata,size)
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_TEXT,tempdata,TAG_END])
Dispose(tempdata)
ENDIF
DisposeObject(newgad)
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_TOP,top,TAG_END])
ENDIF
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_SCROLL ],win,0,[SCROLLER_TOP,top,TAG_END])
ENDPROC
EXPORT PROC close() OF codePreviewForm
RA_CloseWindow(self.windowObj)
ENDPROC
EXPORT PROC show(left,top,width,height) OF codePreviewForm
SetAttrsA(self.windowObj,[
WA_LEFT, left,
WA_TOP, top,
WA_HEIGHT, height,
WA_WIDTH, width,
TAG_DONE])
RA_OpenWindow(self.windowObj)
ENDPROC