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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
| ' Gambas class file
'Static Private $aZoom As Float[]
'Private $sStatus As String 'Private $iZoom As Integer 'Private $iHidden As Integer PRIVATE $sLastLink AS STRING
' Static Public Sub _init() ' ' Dim iInd As Integer ' ' $aZoom = New Float[17] ' ' For iInd = 0 To $aZoom.Max ' $aZoom[iInd] = 2 ^ (- (iInd - $aZoom.Max / 2) / 4) ' Next ' ' End
PUBLIC SUB Form_Open()
WebSettings.IconDatabase.Path = File.Dir(File.Dir(Temp$())) WebSettings.Fonts.FixedFont = "Monospace" WebSettings[WebSettings.PluginsEnabled] = TRUE WebSettings[WebSettings.JavascriptEnabled] = TRUE WebSettings[WebSettings.JavaEnabled] = TRUE WebSettings.Fonts.DefaultFontSize = 12 WebSettings.Fonts.DefaultFixedFontSize = 12
CreateView() btnZoomNormal_Click txtURL.SetFocus tabBrowser_Click
txtURL.Text = "[url=http://gambas.sourceforge.net]http://gambas.sourceforge.net[/url]" txtURL_Activate
END
PRIVATE SUB GetView() AS WebView
TRY RETURN tabBrowser[tabBrowser.Index].Children[0]
END
PRIVATE SUB IsLastCurrentView() AS BOOLEAN
DIM hView AS WebView = GetView()
RETURN hView = LAST
END
PUBLIC SUB WebView_Link(Url AS STRING)
IF NOT IsLastCurrentView() THEN RETURN $sLastLink = Url lblStatus.Text = Url
END
PUBLIC SUB WebView_Status()
IF NOT IsLastCurrentView() THEN RETURN lblStatus.Text = GetView().Status
END
PUBLIC SUB WebView_Progress()
GetView().Status = ("Loading...") IF NOT IsLastCurrentView() THEN RETURN
lblStatus.Text = GetView().Status pgbLoad.Value = GetView().Progress panLoad.Show
END
PUBLIC SUB WebView_Error()
DIM hView AS WebView = GetView() DIM sUrl AS STRING
sUrl = $sLastLink IF NOT sUrl THEN sUrl = txtURL.Text
' If Not (sUrl Begins "www.") Then ' txtURL.Text = "www." & sUrl ' btnGo.Value = True ' Return ' Endif
hView.Status = ("Unable to load:") & " " & sUrl hView.HTML = ("<h3>Unable to find the following URL:</h3>") & sUrl IF NOT IsLastCurrentView() THEN RETURN
lblStatus.Text = GetView().Status pgbLoad.Hide
END
PUBLIC SUB WebView_Load()
'Dim iInd As Integer DIM hView AS WebView = GetView() DIM hIcon AS Picture
hView.Status = "" hIcon = hView.Icon 'WebSettings.IconDatabase[hView.Url] tabBrowser[hView.Tag].Picture = hIcon
IF NOT IsLastCurrentView() THEN RETURN
lblStatus.Text = "" txtURL.Text = hView.Url pgbLoad.Hide
UpdateIcon
' Debug GetView().Frame ' For iInd = 0 To GetView().Frame.Children.Count - 1 ' Debug "["; iInd; "] "; GetView().Frame.Children[iInd] ' Next
END
PUBLIC SUB btnGo_Click()
DIM sText AS STRING = txtURL.Text
IF InStr(sText, "://") = 0 THEN sText = "http://" & sText
$sLastLink = sText GetView().Url = sText
END
PUBLIC SUB txtURL_Activate()
btnGo.Value = TRUE
END
PUBLIC SUB btnBack_Click()
GetView().Back
END
PUBLIC SUB btnForward_Click()
GetView().Forward
END
PUBLIC SUB btnStop_Click()
GetView().Stop
END
PUBLIC SUB btnReload_Click()
DIM hView AS WebView = GetView()
hView.Reload
END
PUBLIC SUB btnZoomIn_Click()
GetView().Zoom = Round(GetView().Zoom * 1.25, -2)
END
PUBLIC SUB btnZoomOut_Click()
GetView().Zoom = Round(GetView().Zoom / 1.25, -2)
END
PUBLIC SUB btnZoomNormal_Click()
GetView().Zoom = 1
END
PUBLIC SUB WebView_Title()
DIM hView AS WebView = LAST
tabBrowser[hView.Tag].Text = hView.Title IF NOT IsLastCurrentView() THEN RETURN ME.Title = hView.Title & " - Gambas WebKit"
END
PUBLIC SUB WebView_Icon()
DIM hView AS WebView = LAST 'hView.Icon.Save("~/icon.png") tabBrowser[hView.Tag].Picture = hView.Icon UpdateIcon
END
PUBLIC SUB btnClear_Click()
txtURL.Clear txtURL.SetFocus
END
PUBLIC SUB WebView_NewWindow((Modal) AS BOOLEAN)
CreateView()
LAST.NewView = GetView()
END
PRIVATE SUB CreateView()
DIM iLast AS INTEGER = tabBrowser.Count - 1 DIM hView AS WebView
Object.Lock(tabBrowser) INC tabBrowser.Count Object.Lock(tabBrowser) tabBrowser[iLast + 1].Picture = tabBrowser[iLast].Picture tabBrowser[iLast + 1].Text = tabBrowser[iLast].Text tabBrowser[iLast].Text = "" tabBrowser[iLast].Picture = NULL tabBrowser[iLast].Closable = TRUE Object.Lock(tabBrowser) tabBrowser.Index = iLast hView = NEW WebView(tabBrowser) AS "WebView" hView.Tag = tabBrowser.Index hView.Editable = btnEdit.Value hView.Resize(1, 1) 'hView.Show 'Print WebSettings.Fonts.FixedFont Object.Unlock(tabBrowser) Object.Unlock(tabBrowser) Object.Unlock(tabBrowser) tabBrowser_Click txtURL.SetFocus
END
PUBLIC SUB tabBrowser_Click()
DIM iLast AS INTEGER = tabBrowser.Count - 1 DIM hView AS WebView
IF tabBrowser.Index = iLast THEN CreateView() ELSE hView = GetView() IF hView.Title THEN ME.Title = hView.Title & " - Gambas WebKit" ELSE ME.Title = "Gambas WebKit" ENDIF tabBrowser.Text = hView.Title UpdateIcon tabBrowser.Picture = hView.Icon txtURL.Text = hView.Url lblStatus.Text = hView.Status pgbLoad.Value = hView.Progress IF hView.Progress > 0 AND IF hView.Progress < 1 THEN panLoad.Show ELSE panLoad.Hide ENDIF ENDIF
END
PUBLIC SUB btnDownloadList_Click()
FDownloadList.Show
END
PUBLIC SUB WebView_Auth()
DIM hView AS WebView = LAST
IF NOT FAuth.Run(hView.Auth.Url, hView.Auth.Realm) THEN
hView.Auth.User = FAuth.User hView.Auth.Password = FAuth.Password 'Debug hView.Auth.Url;; hView.Auth.User;; hView.Auth.Password
ENDIF
END
PUBLIC SUB WebView_Click(Frame AS WebFrame)
DIM sName AS STRING = Frame.Name
IF sName THEN sName &= ": " DEBUG sName; Frame.Url
END
PUBLIC SUB WebView_NewFrame(Frame AS WebFrame)
DEBUG Frame.Name
END
PUBLIC SUB WebView_Download(Download AS WebDownload)
Dialog.Path = System.User.Home &/ File.Name(Download.Url) IF NOT Dialog.SaveFile() THEN Download.Path = Dialog.Path FDownloadList.AddDownload(Download) FDownloadList.Show ENDIF
END
PUBLIC SUB WebView_MouseDown()
DIM hView AS WebView = LAST DIM hTest AS WebHitTest = hView.HitTest(Mouse.X, Mouse.Y) DIM sMsg AS STRING
IF hTest.Document THEN sMsg &= "DOCUMENT " IF hTest.Link THEN sMsg &= "LINK " IF hTest.Image THEN sMsg &= "IMAGE " IF hTest.Selected THEN sMsg &= "SELECTED " IF hTest.Editable THEN sMsg &= "EDITABLE " DEBUG sMsg; hTest.Url
END
PUBLIC SUB tabBrowser_Close(Index AS INTEGER)
DIM hView AS WebView
TRY hView = tabBrowser[Index].Children[0] IF NOT hView THEN RETURN
hView.Delete
Object.Lock(tabBrowser) tabBrowser[Index].Delete Object.UnLock(tabBrowser) IF Index = tabBrowser.Index THEN IF tabBrowser.Index = (tabBrowser.Count - 1) AND IF tabBrowser.Index > 0 THEN tabBrowser.Index = tabBrowser.Index - 1 ELSE tabBrowser_Click ENDIF ENDIF
END
PUBLIC SUB btnFind_Click()
DIM hView AS WebView = GetView()
panFind.Visible = btnFind.Value IF btnFind.Value THEN DoFind txtFind.SetFocus ELSE hView.FindText("") ENDIF
END
PRIVATE SUB DoFind(OPTIONAL bBackward AS BOOLEAN)
DIM hView AS WebView = GetView() DIM sText AS STRING
sText = Trim(txtFind.Text)
IF sText AND IF hView.FindText(sText, bBackward, chkCaseSensitive.Value, TRUE) THEN ', chkHighlight.Value) Then panFind.Background = &HFFDFDF ELSE panFind.Background = Color.Default IF NOT sText THEN hView.FindText("") ENDIF
END
PUBLIC SUB txtFind_Change()
DoFind
END
PUBLIC SUB Form_KeyPress()
IF Key.Control AND IF Key.Code = Key["F"] THEN btnFind.Value = TRUE ELSE IF Key.Code = Key.Escape THEN btnFind.Value = FALSE ELSE IF Key.Code = Key.F3 THEN DoFind(Key.Shift) ENDIF
END
PUBLIC SUB chkCaseSensitive_Click()
DoFind
END
PUBLIC SUB chkHighlight_Click()
DIM hView AS WebView
IF NOT chkHighlight.Value THEN hView = GetView() hView.FindText("",,,, TRUE) ELSE DoFind ENDIF
END
PUBLIC SUB btnNext_Click()
DoFind
END
PUBLIC SUB btnPrevious_Click()
DoFind(TRUE)
END
PUBLIC SUB btnClearFind_Click()
txtFind.Text = ""
END
PUBLIC SUB txtFind_Activate()
DoFind
END
PRIVATE SUB UpdateIcon()
DIM hView AS WebView = GetView() DIM hIcon AS Picture
hIcon = hView.Icon 'WebSettings.IconDatabase[hView.Url]
IF hIcon THEN ME.Icon = hIcon ELSE ME.Icon = Picture["icon:/16/internet"] ENDIF
END
PUBLIC SUB btnConfig_Click()
WITH WebSettings.Proxy
FOption.Type = .Type FOption.Host = .Host FOption.Port = .Port FOption.User = .User FOption.Password = .Password
IF FOption.Run() THEN RETURN
.Type = FOption.Type .Host = FOption.Host .Port = FOption.Port .User = FOption.User .Password = FOption.Password
END WITH
END
PUBLIC SUB btnEdit_Click()
DIM hWebView AS WebView
FOR EACH hWebView IN tabBrowser.Children hWebView.Editable = btnEdit.Value NEXT
WebSettings[WebSettings.JavascriptCanAccessClipboard] = btnEdit.Value panEdit.Visible = btnEdit.Value
END
PUBLIC SUB btnAction_Click()
DIM hWebView AS WebView = GetView()
DEBUG "Action " & LAST.Tag & ": "; hWebView.Eval(Subst("document.execCommand('&1', false, false)", LAST.Tag))
END
PUBLIC SUB btnColor_Click()
DIM hWebView AS WebView = GetView()
IF Dialog.SelectColor() THEN RETURN hWebView.Eval(Subst("document.execCommand('forecolor', false, '&1')", "#" & Hex$(Dialog.Color, 6)))
END
PUBLIC SUB mnuFont_Show()
DIM sFont AS STRING DIM hMenu AS Menu
IF mnuFont.Children.Count > 1 THEN RETURN
mnuFont.Children.Clear
FOR EACH sFont IN Fonts
hMenu = NEW Menu(mnuFont) AS "mnuSelectFont" hMenu.Text = sFont
NEXT
END
PUBLIC SUB mnuSelectFont_Click()
DIM hWebView AS WebView = GetView() DIM sFont AS STRING = LAST.Text
hWebView.Eval(Subst("document.execCommand('fontname', false, '&1')", sFont))
END
PUBLIC SUB btnBackground_Click()
DIM hWebView AS WebView = GetView()
Dialog.Title = ("Select a color") IF Dialog.SelectColor() THEN RETURN hWebView.Eval(Subst("document.execCommand('backcolor', false, '&1')", "#" & Hex$(Dialog.Color, 6)))
END
PUBLIC SUB mnuSelectSize_Click()
DIM hWebView AS WebView = GetView() DIM sSize AS STRING = LAST.Text
hWebView.Eval(Subst("document.execCommand('fontsize', false, '&1')", sSize))
END
PUBLIC SUB btnInsertImage_Click()
DIM hWebView AS WebView = GetView()
Dialog.Title = ("Select an image") Dialog.Filter = ["*.jpg;*.jpeg;*.png;*.gif;*.xpm;*.bmp", "Image files"] IF Dialog.OpenFile() THEN RETURN
PRINT Dialog.Path hWebView.Eval(Subst("document.execCommand('insertImage', false, '&1')", "file://" & Replace(Dialog.Path, "'", "\\'")))
END
|