Menu

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

Download this file

279 lines (233 with data), 7.4 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
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2005-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a COM object that extends a browser control's "external" object
* enabling application code to be called from JavaScript.
}
unit UWBExternal;
interface
uses
// Delphi
ComObj, ActiveX,
// Auto-generated project unit
IntfExternalObj, // derived indirectly from ExternalObj.idl
// Project
IntfNotifier;
type
/// <summary>COM object that implements the methods of the IWBExternal12
/// interface that extend the browser control's 'external' object.</summary>
/// <remarks>
/// <para>This class enables application code to be called from JavaScript
/// running in the browser control.</para>
/// <para>The methods a declared in the type library that is defined in
/// External.idl.</para>
/// </remarks>
TWBExternal = class(TAutoIntfObject, IWBExternal12, ISetNotifier)
strict private
var
/// <summary>Object used to call application code in response to
/// JavaScript calls.</summary>
fNotifier: INotifier;
/// <summary>Handles exceptions raised by getting the application object to
/// handle.</summary>
/// <remarks>Exceptions must be handle by application objects to avoid them
/// causing browser error messages.</remarks>
procedure HandleException;
public
/// <summary>Constructs a new object instance and connects it to the type
/// library.</summary>
constructor Create;
/// <summary>Updates database from internet.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure UpdateDbase; safecall;
/// <summary>Displays a named snippet.</summary>
/// <param name="SnippetName">WideString [in] Name of snippet to be
/// displayed.</param>
/// <param name="UserDefined">WordBool [in] Whether the snippet is user
/// defined.</param>
/// <param name="NewTab">WordBool [in] Whether to display snippet in a new
/// tab.</param>
/// <remarks>Method of IWBExternal12.</remarks>
procedure DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool; NewTab: WordBool); safecall;
/// <summary>Displays the Configure Compilers dialogue box.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure ConfigCompilers; safecall;
/// <summary>Edits a named snippet.</summary>
/// <param name="SnippetName">WideString [in] Name of snippet to be edited.
/// </param>
/// <remarks>
/// <para>The named snippet must be user defined.</para>
/// <para>Method of IWBExternal12.</para>
/// </remarks>
procedure EditSnippet(const SnippetName: WideString); safecall;
/// <summary>Displays the Donate dialogue box.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure Donate; safecall;
/// <summary>Displays a named category.</summary>
/// <param name="CatID">WideString [in] ID of category to be displayed.
/// </param>
/// <param name="NewTab">WordBool [in] Whether to display category in a new
/// tab.</param>
/// <remarks>Method of IWBExternal12.</remarks>
procedure DisplayCategory(const CatID: WideString; NewTab: WordBool);
safecall;
/// <summary>Opens Snippet Editor ready to create a new snippet.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure NewSnippet; safecall;
/// <summary>Shows latest news items from CodeSnip news feed.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure ShowNews; safecall;
/// <summary>Checks for program updates.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure CheckForUpdates; safecall;
/// <summary>Displays the program's About Box.</summary>
/// <remarks>Method of IWBExternal12.</remarks>
procedure ShowAboutBox; safecall;
/// <summary>Displays specified page of the Preferences dialogue.</summary>
/// <param name="ClsName">WideString [in] Class name of the frame that
/// implements the required preferences page.</param>
/// <remarks>Method of IWBExternal12.</remarks>
procedure ShowPrefsPage(const ClsName: WideString); safecall;
/// <summary>Records the notifier object that is used to call application
/// code in response to JavaScript calls running in browser documents.
/// </summary>
/// <param name="Notifier">INotifier [in] The notifier object.</param>
/// <remarks>Method of ISetNotifier.</remarks>
procedure SetNotifier(const Notifier: INotifier);
end;
implementation
uses
// Delphi
Forms,
// Project
UAppInfo;
{ TWBExternal }
procedure TWBExternal.CheckForUpdates;
begin
try
if Assigned(fNotifier) then
fNotifier.CheckForUpdates;
except
HandleException;
end;
end;
procedure TWBExternal.ConfigCompilers;
begin
try
if Assigned(fNotifier) then
fNotifier.ConfigCompilers;
except
HandleException;
end;
end;
constructor TWBExternal.Create;
var
TypeLib: ITypeLib; // type library
ExeName: WideString; // name of this executable file
begin
// Get type library info from exe file
ExeName := TAppInfo.AppExeFilePath;
OleCheck(LoadTypeLib(PWideChar(ExeName), TypeLib));
// Create the object using type library
inherited Create(TypeLib, IWBExternal12);
end;
procedure TWBExternal.DisplayCategory(const CatID: WideString;
NewTab: WordBool);
begin
try
if Assigned(fNotifier) then
fNotifier.DisplayCategory(CatID, NewTab);
except
HandleException;
end;
end;
procedure TWBExternal.DisplaySnippet(const SnippetName: WideString;
UserDefined: WordBool; NewTab: WordBool);
begin
try
if Assigned(fNotifier) then
fNotifier.DisplaySnippet(SnippetName, UserDefined, NewTab);
except
HandleException;
end;
end;
procedure TWBExternal.Donate;
begin
try
if Assigned(fNotifier) then
fNotifier.Donate;
except
HandleException;
end;
end;
procedure TWBExternal.EditSnippet(const SnippetName: WideString);
begin
try
if Assigned(fNotifier) then
fNotifier.EditSnippet(SnippetName);
except
HandleException;
end;
end;
procedure TWBExternal.HandleException;
begin
Application.HandleException(ExceptObject);
end;
procedure TWBExternal.NewSnippet;
begin
try
if Assigned(fNotifier) then
fNotifier.NewSnippet;
except
HandleException;
end;
end;
procedure TWBExternal.SetNotifier(const Notifier: INotifier);
begin
fNotifier := Notifier;
end;
procedure TWBExternal.ShowAboutBox;
begin
try
if Assigned(fNotifier) then
fNotifier.ShowAboutBox;
except
HandleException;
end;
end;
procedure TWBExternal.ShowNews;
begin
try
if Assigned(fNotifier) then
fNotifier.ShowNews;
except
HandleException;
end;
end;
procedure TWBExternal.ShowPrefsPage(const ClsName: WideString); safecall;
begin
try
if Assigned(fNotifier) then
fNotifier.ShowPrefsPage(ClsName);
except
HandleException;
end;
end;
procedure TWBExternal.UpdateDbase;
begin
try
if Assigned(fNotifier) then
fNotifier.UpdateDbase;
except
HandleException;
end;
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.