-
Notifications
You must be signed in to change notification settings - Fork 1
/
BBjDocViewer.bbj
220 lines (186 loc) · 6.84 KB
/
BBjDocViewer.bbj
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
218
219
220
use com.basiscomponents.db.ResultSet
use com.basiscomponents.db.DataRow
use com.basiscomponents.db.tree.DataTree
use java.sql.Types
use com.google.gson.Gson
use com.google.gson.JsonParser
use com.google.gson.JsonObject
use com.google.gson.JsonArray
use java.lang.Integer
use java.util.ArrayList
use java.util.HashMap
use java.lang.Object
use java.io.File
use com.basis.bbj.proxies.event.BBjCustomEvent
use com.basiscomponents.comm.WsServer
use com.basiscomponents.comm.CrossEventDispatcher
use ::BBjWidget/BBjWidget.bbj::BBjWidget
class public BBjDocViewer extends BBjWidget
field protected BBjHtmlView HTMLView!
field protected Boolean IsViewerInitialized! = BBjAPI.FALSE
field protected Boolean IsOpening! = BBjAPI.FALSE
field protected BBjVector backlog! = new BBjVector()
field protected BBjString Tag$
field protected WsServer WS!
field protected ResultSet RS!
field protected Boolean Toolbar! = BBjAPI.TRUE
field protected Boolean HandTool! = BBjAPI.FALSE
field protected BBjToolButton TbPrint!
rem /**
rem * disabled default constructor
rem */
method private BBjDocViewer()
methodend
rem /**
rem * The constructor that creates the widget on wnd!
rem * @param BBjWindow wnd!: parent window
rem * @param BBjInt id: the control ID
rem * @param BBjInt x: x-location
rem * @param BBjInt y: y-location
rem * @param BBjInt w: width
rem * @param BBjInt h: height
rem */
method public BBjDocViewer(BBjWindow wnd!, BBjNumber id!, BBjNumber x!, BBjNumber y!, BBjNumber w!, BBjNumber h!)
#super!.create(wnd!,id!,x!,y!,w!,h!)
methodend
method public BBjDocViewer(BBjChildWindow wnd!)
#setCanvas(wnd!)
#super!.setX(wnd!.getX())
#super!.setY(wnd!.getY())
#super!.setW(wnd!.getWidth())
#super!.setH(wnd!.getHeight())
#redraw(BBjAPI.TRUE)
methodend
rem /**
rem * @Override
rem * This method is called whenever the widget needs to be rendered
rem * @param Boolean init!: if TRUE trem /**
rem *
rem * control is rendered for the first time so this method has to perform initial rendering
rem */
method public void redraw(Boolean init!)
declare BBjHtmlView htmlview!
if (init!) then
htmlview! = #getCanvas().addHtmlView(101,0,0,#getCanvas().getWidth(),#getCanvas().getHeight(),"")
if (info(3,6)="6" AND AND(#getCanvas().getWindowFlags(),$00100000$) = $00100000$) then
rem in DWC, if parent window is client-side sized, make the htmlview same size as surrunding canvas
htmlview!.setStyle("width","100%")
htmlview!.setStyle("height","100%")
fi
#HTMLView!=htmlview!
if (htmlview!.getClientType() <> "Chromium" AND INFO(3,6)<>"5" AND INFO(3,6)<>"6")
htmlview!.setText("<html><center>Error: Need the Chromium Engine in BBj 18.10 or later. Please check your BBj SAM coverage!</center></html>")
else
htmlview!.setOpaque(0)
fi
if INFO(3,6)<>"5" and INFO(3,6)<>"6" then
#HTMLView!.setLocation(-9,-9)
FI
icon$ = BBjAPI().getFileSystem().resolvePath("BBjDocViewer/res/printer.png")
#TbPrint! = #getCanvas().addToolButton(300,#getCanvas().getWidth()-50,10,35,35,"BITMAP="+icon$,$0010$)
#TbPrint!.setOpaque(1)
#TbPrint!.setVisible(0)
#TbPrint!.setCallback(BBjAPI.ON_TOOL_BUTTON_PUSH,#this!,"onPrint")
FI
if INFO(3,6)="5" OR INFO(3,6)="6" then
#HTMLView!.setSize(#getCanvas().getWidth(),#getCanvas().getHeight())
else
#HTMLView!.setSize(#getCanvas().getWidth()+16,#getCanvas().getHeight()+16)
FI
#TbPrint!.setLocation(#getCanvas().getWidth()-50,10)
methodend
rem /**
rem * openBlob: open a document directly from a blob in memory
rem *
rem * @param BBjString blob$ : the document as binary string
rem * @param BBjString name$ : the file name under which the file should be served
rem *
rem * The approrpiate viewer will be determined as of the extention of the name$
rem */
method public void openBlob(BBjString blob$,BBjString name$)
tmpdir$ = System.getProperty("java.io.tmpdir")
if new File(tmpdir$+name$).exists() then
d! = java.nio.file.Files.createTempDirectory("__fviewer")
tmpdir$ = d!.toAbsolutePath().toString()+"/"
fi
path$=tmpdir$+name$
f! = new File(path$)
f!.deleteOnExit()
ch=unt
open (ch,mode="O_TRUNC, O_CREATE")path$
write (ch)blob$
close (ch)
#open(path$)
methodend
rem /**
rem * open: open a document directly from a phyiscal file on disk
rem *
rem * @param BBjString file$ : the file name under which the file should be served
rem *
rem * The approrpiate viewer will be determined as of the extention of the name$
rem */
method public void open(BBjString file$)
ext$=#getExtension(file$)
clean$=file$
while pos("/"=clean$)>0
clean$=clean$(pos("/"=clean$)+1)
wend
while pos("\"=clean$)>0
clean$=clean$(pos("\"=clean$)+1)
wend
while pos("#"=clean$)>0
clean$=clean$(1,pos("#"=clean$)-1)
wend
if (INFO(3,6)<>"5" AND INFO(3,6)<>"6") OR REV>= "REV 20.12" then
if (ext$<>"PDF") then
#TbPrint!.setVisible(1)
else
#TbPrint!.setVisible(0)
fi
fi
switch ext$
case "TXT"
case "CSV"
case "HTML"
case "HTM"
ch = unt
open (ch)file$
f$= fin(ch)
l=dec(f$(1,4))
read record (ch,siz=l)text$
close (ch)
#HTMLView!.setText(text$)
break
case "PDF"
path$=::BBUtils.bbj::BBUtils.copyFileToWebServer(file$, "deliver", clean$, 0, 1)
#HTMLView!.setUrl(path$)
break
case default
ch = unt
open (ch)file$
f$= fin(ch)
l=dec(f$(1,4))
read record (ch,siz=l)text$
close (ch)
#HTMLView!.setText(text$)
break
swend
methodend
rem /**
rem *
rem */
method public void onPrint(BBjToolButtonPushEvent ev!)
#HTMLView!.print()
methodend
method private BBjString getExtension(BBjString file$)
ext$ = file$
while pos("."=ext$)>0
ext$=ext$(pos("."=ext$)+1)
wend
while pos("#"=ext$)>0
ext$=ext$(1,pos("#"=ext$)-1)
wend
ext$=cvs(ext$,4)
methodret ext$
methodend
classend