-
Notifications
You must be signed in to change notification settings - Fork 26
/
scide.htm
582 lines (502 loc) · 16 KB
/
scide.htm
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
582
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SciDe examples</title>
<style>
@import url(res:richtext.css);
//@import url(res:plus.css);
h2
{
margin-top: 2cm;
}
div.out, pre.out
{
padding: 10px;
margin: 10px;
min-height: 40px;
border: 1px dotted #999999;
background-color: #FFFFCC;
}
pre.code
{
padding: 10px;
margin: 10px;
font-family: "Courier New";
font-size: 9pt;
}
</style>
<script type="text/tiscript">
//include "res:plus.tis";
function Echo(a)
{
return a;
}
function sciter_sum(a, b)
{
return a + b;
}
function self#cmdXml.onClick()
{
self#preXML.text = XML.xml;
}
function self#cmdMSXML.onClick()
{
var doc = CreateObject("MSXML2.DOMDocument");
doc.loadXML("<div />");
var root = doc.documentElement;
for (var i = 0; i < 10; i++)
{
var heading = root.appendChild(doc.createElement("h"));
var textNode = heading.appendChild(doc.createTextNode("Heading " + i));
}
var doc1 = doc;
self.select("#oleOut1").text = doc1.xml;
doc1 = null;
doc = null;
}
function self#cmdRegExp.onClick()
{
var re = CreateObject("VBScript.RegExp");
re.Pattern = "\\d+";
re.Global = true;
var arr = [];
var matches = re.Execute(self#txtRegExpInp.text);
for (var match in matches)
{
arr.push(match.Value);
}
self.select("#oleOut2").text = "Found numeric values: " + arr.join(", ");
matches = null;
re = null;
}
var word;
function self#cmdOpenWord.onClick()
{
word = CreateObject("Word.Application");
word.Visible = true;
var doc = word.Documents.Add();
doc.Paragraphs[doc.Paragraphs.Count].Range.Text = "Hello from Sciter!";
}
function self#cmdCloseWord.onClick()
{
if (word)
{
word.Quit(false);
word = null;
}
}
function self#cmdTestSayHello.onClick()
{
var x = Test;
x.SayHello();
}
function self#cmdCallNativeFunction.onClick()
{
SayHello();
}
var frm;
function self#cmdShowNativeForm.onClick()
{
if (frm == null)
{
frm = new NativeForm();
frm.Show();
}
}
function self#cmdCloseNativeForm.onClick()
{
if (frm)
{
frm.Close();
frm = null;
}
}
function self#cmdShowRichText.onClick()
{
self#richOut.text = self#txtRich.text;
}
function self#cmdShowRichHTML.onClick()
{
self#richOut.text = self#txtRich.value;
}
function self#cmdPrintOut.onClick()
{
stdout.println("An info message from Sciter");
}
function self#cmdPrintError.onClick()
{
stderr.println("An error from Sciter");
}
function self#cmdPopup.onClick()
{
view.msgbox(#alert, "Can you close this?");
}
function self#cmdViewFoo.onClick()
{
var x = view.Foo();
stdout.println(x);
}
function self#cmdViewFoo2.onClick()
{
view.Foo2("Hello World!");
}
function self#cmdBodyFoo.onClick()
{
self.select("body").Foo("body.Foo() called");
}
function self#cmdBodyFoo2.onClick()
{
self.select("body").Foo2("body.Foo2() called");
}
function self.ready()
{
for (var pre in self.selectAll("pre.code"))
{
pre.$before(<div><strong>Code example</strong></div>);
}
for (var pre in self.selectAll("pre.out, div.out"))
{
pre.$before(<div><strong>Output</strong></div>);
}
var i = 0;
for (var h in self.selectAll("h2"))
{
var anchor_html = "<a name='toc" + i + "' />";
h.append(anchor_html);
var link_html = "<li><a href='#toc" + i + "'>" + h.text + "</a></li>";
self#menu.append(link_html);
i++;
}
}
function self#cmdSciterAlert.onClick()
{
view.msgbox(#alert, "Sciter");
}
function self#cmdDemoBehaviorGetValue.onClick()
{
view.msgbox(#alert, self#divDemoBehavior.value);
}
</script>
</head>
<body>
<h1>SCIDE - Sciter for Delphi</h1>
<section>
<div style="background-color: #FFCC66; padding: 10pt; margin: 10pt; font-size: 14pt">You can find more samples in the Sciter SDK (http://sciter.com) </div>
</section>
<strong>Table of Contents</strong>
<ul id="menu">
</ul>
<!--************************************************************************-->
<section>
<h2>Basic DOM manipulations</h2>
<button id="cmdCreateHeadings">Create headings</button>
<button id="cmdCloneHeadings">Clone first 10 headings</button>
<button id="cmdChangeHeadingsText">Change headings text</button>
<button id="cmdRemoveHeadings">Remove headings</button>
<button id="cmdSetHeadingsColor">Batch element processing using ForAll method with callback</button>
<pre id="divHeadings" class="out">
</pre>
</section>
<!--************************************************************************-->
<section>
<h2>Event handling using IElementEvents interface</h2>
<input type="text" id="txtEvents" style="width: 50%" value="This input has event handlers attached" />
</section>
<!--************************************************************************-->
<section>
<h2>Event handling using IElement.Subscribe* functions</h2>
<table>
<tr><td>input|text:</td><td><input class="es" /></td></tr>
<tr><td>input|checkbox:</td><td><input type="checkbox" class="es" /></td></tr>
<tr><td>textarea:</td><td><textarea class="es"></textarea></td></tr>
<tr><td>button</td><td><button class="es1">Click me</button></td></tr>
<tr><td>Type something here:</td><td><input class="es2" /></td></tr>
</table>
</section>
<!--************************************************************************-->
<section>
<h2>Event handlers assigned at design-time (see TSciter.EventMap collection)</h2>
<div>
<button id="cmdEventHandler">I'm #cmdEventHandler. Click me</button>
<button class="cmd-event-handler">My class is "cmd-event-handler". Click me</button>
<button class="cmd-event-handler">My class is "cmd-event-handler". Click me</button>
<button class="cmd-event-handler">My class is "cmd-event-handler". Click me</button>
</div>
</section>
<!--************************************************************************-->
<section>
<h2>OLE Example 1. Creating and manipulating XML document using MSXML</h2>
<pre class="code">
var doc = CreateObject("MSXML2.DOMDocument");
doc.loadXML("<div />");
var root = doc.documentElement;
for (var i = 0; i < 10; i++)
{
var heading = root.appendChild(doc.createElement("h"));
var textNode = heading.appendChild(doc.createTextNode("Heading " + i));
}
var doc1 = doc;
self.select("#oleOut1").text = doc1.xml;
doc1 = null;
doc = null;
</pre>
<button id="cmdMSXML">Run MSXML</button>
<pre id="oleOut1" class="out">
</pre>
</section>
<!--************************************************************************-->
<section>
<h2>OLE Example 2. Parsing text with regular expressions</h2>
<pre class="code">
var re = CreateObject("VBScript.RegExp");
re.Pattern = "\\d+";
re.Global = true;
var arr = [];
var matches = re.Execute(self#txtRegExpInp.text);
for (var match in matches)
{
arr.push(match.Value);
}
self.select("#oleOut2").text = "Found numeric values: " + arr.join(", ");
matches = null;
re = null;
</pre>
<div>
<button id="cmdRegExp">Run VBScript.RegExp</button>
</div>
<div>
<textarea id="txtRegExpInp" style="width: 80%; height: 200px">
US oilfield services firm Halliburton has said it will cut up to 8% of its global workforce of 80,000,
citing a "challenging market environment" as the oil price continues to tumble. Halliburton says the
cuts will be across all operations of the company.
Shares in Halliburton - the world's second-largest oilfield services company -
fell nearly 3%. The oil price has nearly halved since June as a global supply glut
and weak demand push prices down. "We value every employee we have, but unfortunately we are
faced with the difficult reality that reductions are necessary to work through this challenging market environment,"
said Halliburton in a statement to the BBC. Halliburton had previously announced that it was planning job
cuts in a conference call to discuss earnings on 20 January. The company reported fourth quarter profits
of $901m (£591m), a 14% increase from the same period a year earlier.</textarea>
</div>
<pre id="oleOut2" class="out">
</pre>
</section>
<!--************************************************************************-->
<section>
<h2>OLE Example 3. Call Microsoft Word</h2>
<pre class="code">
var word = CreateObject("Word.Application");
word.Visible = true;
var doc = word.Documents.Add();
doc.Paragraphs[doc.Paragraphs.Count].Range.Text = "Hello from Sciter!";
</pre>
<button id="cmdOpenWord">Run Microsoft Word</button>
<button id="cmdCloseWord">Close Microsoft Word</button>
</section>
<section>
<h2>OLE Example 4. Invoke externally passed COM object</h2>
<pre class="code">
// Delphi code
procedure TMainForm.FormCreate(Sender: TObject);
var
pTest: ITest; // the ITest interface inherits from IDispatch
begin
pTest := TTest.Create;
Sciter1.RegisterComObject('Test', pTest);
end;
// TIScript code
function self#cmd.onClick()
{
Test.SayHello();
}
</pre>
<button id="cmdTestSayHello">Invoke Test.SayHello</button>
</section>
<!--************************************************************************-->
<section>
<h2>OLE Example 5. Invoke another externally passed COM object</h2>
<pre class="code">
// Delphi code
pXml := CreateOleObject('MSXML2.DOMDocument');
pXml.LoadXML('...');
Sciter1.RegisterComObject('XML', pXml);
// TIScript code
function self#cmdXml.onClick()
{
self#preXML.text = XML.xml;
}
</pre>
<pre id="preXML">
</pre>
<button id="cmdXml">Get MSXML2.DOMDocument xml</button>
</section>
<!--************************************************************************-->
<section>
<h2>Intercept non-existing view methods calls</h2>
<pre class="code">
// The Foo function does not exist in the view context, but you
// can intercept and handle that function call
procedure TMainForm.Sciter1MethodCall(ASender: TObject; const MethodName:
WideString; const Args: array of OLEVariant; var ReturnValue: OleVariant;
var Handled: Boolean);
begin
if MethodName = 'Foo' then
begin
ShowMessage('Method ' + MethodName + ' is calling with argument ' + Args[0]);
Handled := True;
end;
// else Handled = False and Sciter will emit a warning message
end;
</pre>
<button id="cmdViewFoo">Call view.Foo()</button>
<button id="cmdViewFoo2">Call view.Foo2() (handler does not exist)</button>
</section>
<!--************************************************************************-->
<section>
<h2>Intercept element methods calls</h2>
<button id="cmdBodyFoo">Call body.Foo()</button>
<button id="cmdBodyFoo2">Call body.Foo2() (handler does not exist)</button>
</section>
<!--************************************************************************-->
<section>
<h2>Call native function implemented in Delphi</h2>
<pre class="code">
function SayHelloNative(c: HVM): tiscript_value; cdecl;
begin
ShowMessage('Hello!');
Result := NI.int_value(0);
end;
...
Sciter1.RegisterNativeFunction('SayHello', @SayHelloNative);
</pre>
<button id="cmdCallNativeFunction">Say hello</button>
</section>
<!--************************************************************************-->
<section>
<h2>Call native class implemented in Delphi</h2>
<button id="cmdShowNativeForm">Show native form</button>
<button id="cmdCloseNativeForm">Close native form</button>
</section>
<!--************************************************************************-->
<section>
<h2>Native Delphi Control inside Sciter</h2>
<pre class="code">
procedure TMainForm.Sciter1DocumentComplete(ASender: TObject; const url:
WideString);
var
pButton: TButton;
pDivContainer: TElement;
begin
pDivContainer := Sciter1.Root.Select('#divContainer');
if pDivContainer <> nil then
begin
pButton := TButton.Create(Self);
pButton.Parent := Sciter1;
pButton.Caption := 'Native button';
pButton.OnClick := OnNativeButtonClick;
pButton.Font.Color := clGreen;
pDivContainer.AttachHwndToElement(pButton.Handle);
end;
end;
</pre>
<div id="divContainer" style="width: 50%; height: 30px">
</div>
</section>
<!--************************************************************************-->
<section>
<h2>Richtext behavior (embedded in Resources)</h2>
<div>
<button id="cmdShowRichText">Show richedit text</button>
<button id="cmdShowRichHTML">Show richedit HTML</button>
<richtext style="height: 150px" id="txtRich">
<h4>SciDe</h4>
<a href="http://terrainformatica.com/sciter">Sciter</a>
</richtext>
<pre id="richOut" class="out">
</pre>
</div>
</section>
<!--************************************************************************-->
<section>
<h2>Dump this Document DOM tree</h2>
<button id="cmdDump">Run</button>
<pre id="preDump" class="out">
</pre>
</section>
<!--************************************************************************-->
<section>
<h2>Print something</h2>
<button id="cmdPrintOut">An info message</button>
<button id="cmdPrintError">An error message</button>
<button id="cmdSciterAlert">Show alert</button>
</section>
<!--************************************************************************-->
<section>
<h2>Popups problem (resolved)</h2>
<button id="cmdPopup">Show alert</button>
</section>
<!--************************************************************************-->
<section>
<h2>Native behavior demo</h2>
<pre class="code">
<!-- HTML -->
<div style="behavior: DemoBehavior" id="divDemoBehavior"/>
{ Delphi code }
TDemoBehavior = class(TElement)
...
class function TDemoBehavior.BehaviorName: AnsiString;
begin
Result := 'DemoBehavior';
end;
...
initialization
<b>SciterRegisterBehavior(TDemoBehavior);</b>
</pre>
<div style="behavior: DemoBehavior" id="divDemoBehavior">
</div>
<button id="cmdDemoBehaviorGetValue">Show value</button>
</section>
<!--************************************************************************-->
<section>
<h2>Filtering behavior events</h2>
<textarea id="divSubscriptionRequest" style="background-color: lime; width: 100%; height: 200px; behavior: EventFilter">
</textarea>
</section>
<!--************************************************************************-->
<!--section>
<h2>Embedded Flash player (experimental)</h2>
<div id="divFlash" style="behavior: FlashPlayer; width: 600px; height: 400px" src="construction.swf">
</div>
</section-->
<!--************************************************************************-->
<section>
<h2>Timer demo</h2>
<button id="cmdStartTimer">Start timer</button>
<button id="cmdStopTimer">Stop timer</button>
<div id="divTimer" class="out">
</div>
</section>
<!--************************************************************************-->
<section>
<h2>Request demo</h2>
<button id="cmdRequest">Perform HTTP request</button>
<div id="divRequest" class="out">
</div>
</section>
<!--************************************************************************-->
<section>
<h2>Insert before/after</h2>
<button id="cmdInsertBefore">Insert before</button>
<button id="cmdInsertAfter">Insert after</button>
<span id="spanBeforeAfter">|text|</span>
</section>
<!--************************************************************************-->
<section>
<h2>Custom URL protocol handler</h2>
<pre class="code">
<img src="scide://scide.png" />
</pre>
<img src="scide://scide.png" />
</section>
</body>
</html>