Menu

[r181]: / trunk / Src / UWBExternal.pas  Maximize  Restore  History

Download this file

285 lines (255 with data), 9.9 kB

  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
{
* UWBExternal.pas
*
* COM object that extends the "external" object accessible from JavaScript in a
* browser control and notifies application of events triggered via JavaScript
* calls to the external object's methods.
*
* v0.1 of 22 Feb 2005 - Original version. Replaced former UExtInfo and
* UExtCompCheck units that provided different external
* object extensions for different browser controls.
* v0.2 of 25 Apr 2005 - Implemented new HelpTopic and ConfigCompilers methods
* of IWBExternal by calling methods of same names in
* notifier object.
* - Deleted implementation QuickStartHelp method that was
* removed from IWBExternal.
* - Added new InstalledCompilers method of IWBExternal
* that returns number of available compilers to
* JavaScript.
* v0.3 of 03 Jun 2005 - Deleted InstalledCompilers method since no longer
* required.
* v1.0 of 05 Jun 2006 - Improved and corrected comments.
* - Relocated and rationalised $WARN directives.
* - Removed unused unit reference.
* - Changed to get path to executable file from TAppInfo
* static class rather than direct.
* - Changed to use renamed IntfExternalObj unit (was
* previously CodeSnip_TLB).
* v1.1 of 23 Nov 2006 - Added ToggleTestUnit method and implemented by calling
* equivalent method in notifier object.
* - Changed to support IWBExternal2 instead of
* IWBExternal.
* v1.2 of 04 Nov 2007 - Changed to implement IWBExternal3 instead of
* IWBExternal2 and removed HelpTopic method as
* consequence.
* v1.3 of 14 Sep 2008 - Changed to implement IWBExternal4 instead of
* IWBExternal3:
* - Changed signature of DisplayRoutine and modified the
* implementation to call the equivalent modified
* notifier method.
* - Added new EditRoutine method that calls method of
* same name in Notifier.
* v1.4 of 17 Jun 2009 - Changed to implement IWBExternal5 instead of
* IWBExternal4:
* - ShowTestUnit method replaces ToggleTestUnit.
* - Donate method added.
* - Renamed DisplayRoutine method as DisplaySnippet,
* CompileRoutine as CompileSnippet, EditRoutine as
* EditSnippet.
* - Made private section strict.
* v1.5 of 12 Jul 2009 - Changed to implement IWBExternal6 instead of
* IWBExternal5 by adding DisplayCategory method.
*
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is UWBExternal.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2005-2009 Peter
* Johnson. All Rights Reserved.
*
* ***** END LICENSE BLOCK *****
}
unit UWBExternal;
interface
uses
// Delphi
ComObj, ActiveX,
// Auto-generated project unit
IntfExternalObj, // derived indirectly from ExternalObj.idl
// Project
IntfNotifier;
type
{
TWBExternal:
COM object that extends the "external" object accessible from JavaScript in
a web browser and notifies application of events triggered via JavaScript
calls to the external object's methods. Uses notification object to pass
events to application.
}
TWBExternal = class(TAutoIntfObject,
IWBExternal6, // browser external object's methods
ISetNotifier // sets object used to notify app of events
)
strict private
fNotifier: INotifier; // Notifies application of events triggered by user
protected // do not make strict
{ IWBExternal5: defined in type library }
procedure UpdateDbase; safecall;
{Updates database from internet via notifier.
}
procedure DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool); safecall;
{Displays the named snippet via notifier.
@param SnippetName [in] Name of snippet to display.
@param UserDefined [in] Whether snippet is user defined.
}
procedure CompileSnippet; safecall;
{Compiles the current snippet via notifier.
}
procedure ViewCompilerLog(Ver: SYSINT); safecall;
{Displays a compiler log via notifier.
@param Ver [in] Version of Delphi for which we need to display log. Ver
is the ordinal value of the required compiler version enumerated type.
}
procedure ShowHint(const Hint: WideString); safecall;
{Displays the given hint via notifier.
@param Hint [in] Hint to be displayed.
}
procedure ConfigCompilers; safecall;
{Displays configure compilers dialog box via notifier.
}
procedure ShowTestUnit; safecall;
{Display the test unit for current snippet.
}
procedure EditSnippet(const SnippetName: WideString); safecall;
{Edits the named snippet.
@param SnippetName [in] Name of snippet to be edited. Must be a user
defined snippet.
}
procedure Donate; safecall;
{Displays the Donate dialog box via notifier.
}
procedure DisplayCategory(const CatID: WideString); safecall;
{Displays a category via notifier.
@param CatID [in] ID of category to display.
}
{ ISetNotifier }
procedure SetNotifier(const Notifier: INotifier);
{Sets the object's notifier object that is called in response to user
input.
@param Notifier [in] Notifier object.
}
public
constructor Create;
{Class constructor. Sets up object using embedded type library.
}
end;
implementation
uses
// Project
UAppInfo, UUtils;
{ TWBExternal }
procedure TWBExternal.CompileSnippet;
{Compiles the current snippet via notifier.
}
begin
if Assigned(fNotifier) then
fNotifier.CompileRoutine;
end;
procedure TWBExternal.ConfigCompilers;
{Displays configure compilers dialog box via notifier.
}
begin
if Assigned(fNotifier) then
fNotifier.ConfigCompilers;
end;
constructor TWBExternal.Create;
{Class constructor. Sets up object using embedded type library.
}
var
TypeLib: ITypeLib; // type library
ExeName: WideString; // name of this executable file
begin
// Get type library info from exe file
ExeName := DirToPath(TAppInfo.AppExeDir) + TAppInfo.AppExeFile;
OleCheck(LoadTypeLib(PWideChar(ExeName), TypeLib));
// Create the object using type library
inherited Create(TypeLib, IWBExternal6);
end;
procedure TWBExternal.DisplayCategory(const CatID: WideString);
{Displays a category via notifier.
@param CatID [in] ID of category to display.
}
begin
if Assigned(fNotifier) then
fNotifier.DisplayCategory(CatID);
end;
procedure TWBExternal.DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool);
{Displays the named snippet via notifier.
@param SnippetName [in] Name of snippet to display.
@param UserDefined [in] Whether snippet is user defined.
}
begin
if Assigned(fNotifier) then
fNotifier.DisplayRoutine(SnippetName, UserDefined);
end;
procedure TWBExternal.Donate;
{Displays the Donate dialog box via notifier.
}
begin
if Assigned(fNotifier) then
fNotifier.Donate;
end;
procedure TWBExternal.EditSnippet(const SnippetName: WideString);
{Edits the named snippet.
@param SnippetName [in] Name of snippet to be edited. Must be a user defined
snippet.
}
begin
if Assigned(fNotifier) then
fNotifier.EditRoutine(SnippetName);
end;
procedure TWBExternal.SetNotifier(const Notifier: INotifier);
{Sets the object's notifier object that is called in response to user input.
@param Notifier [in] Notifier object.
}
begin
fNotifier := Notifier;
end;
procedure TWBExternal.ShowHint(const Hint: WideString);
{Displays the given hint via notifier.
@param Hint [in] Hint to be displayed.
}
begin
if Assigned(fNotifier) then
fNotifier.ShowHint(Hint);
end;
procedure TWBExternal.ShowTestUnit;
{Display the test unit for current snippet.
}
begin
if Assigned(fNotifier) then
fNotifier.ShowTestUnit;
end;
procedure TWBExternal.UpdateDbase;
{Updates database from internet via notifier.
}
begin
if Assigned(fNotifier) then
fNotifier.UpdateDbase;
end;
procedure TWBExternal.ViewCompilerLog(Ver: SYSINT);
{Displays a compiler log via notifier.
@param Ver [in] Version of Delphi for which we need to display log. Ver is
the ordinal value of the required compiler version enumerated type.
}
begin
if Assigned(fNotifier) then
fNotifier.ViewCompilerLog(Ver);
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.