@@ -394,13 +394,18 @@ use com.livecode.foreign
394394use com.livecode.canvas
395395use com.livecode.engine
396396
397+ // ---------- Widget type definition ---------- //
398+
399+ public foreign type Widget binds to "MCWidgetTypeInfo"
400+
397401// ---------- Widget commands ---------- //
398402
399403public foreign handler MCWidgetExecRedrawAll() returns nothing binds to "<builtin>"
400404public foreign handler MCWidgetExecScheduleTimerIn(in pTime as CDouble) returns nothing binds to "<builtin>"
401405public foreign handler MCWidgetExecCancelTimer() returns nothing binds to "<builtin>"
402406public foreign handler MCWidgetEvalInEditMode(out rInEditMode as CBool) returns nothing binds to "<builtin>"
403407public foreign handler MCWidgetExecTriggerAll() returns nothing binds to "<builtin>"
408+ public foreign handler MCWidgetExecTriggerAllInWidget(in pWidget as Widget) returns nothing binds to "<builtin>"
404409
405410/**
406411Summary: Redraws the widget.
@@ -488,23 +493,32 @@ end syntax
488493
489494/**
490495Summary: Causes all of a widget's property triggers to be fired.
496+ mWidget: An expression that evaluates to a widget.
491497
492498Example:
493499 handler TextChangedCallback()
494500 UpdateTextProperty()
495501 trigger all
496502 end handler
497503
504+ Example:
505+ private variable mSelf as Widget
506+ handler TextChangedCallback()
507+ UpdateTextProperty()
508+ trigger all in mSelf
509+ end handler
510+
498511Description:
499512Use trigger all to cause all triggers for all a widget's properties to
500513be fired, for example when user action causes a native widget's
501514properties to change, to signal the property change to the IDE.
502515*/
503516
504517syntax TriggerAll is statement
505- "trigger" "all"
518+ "trigger" "all" [ "in" <mWidget: Expression> ]
506519begin
507520 MCWidgetExecTriggerAll()
521+ MCWidgetExecTriggerAllInWidget(mWidget)
508522end syntax
509523
510524
@@ -1164,8 +1178,7 @@ end syntax
11641178
11651179// annotation <name> of <widget>
11661180
1167- public foreign type Widget binds to "MCWidgetTypeInfo"
1168-
1181+ public foreign handler MCWidgetEvalThisWidget(out rMe as optional Widget) returns nothing binds to "<builtin>"
11691182public foreign handler MCWidgetEvalTheTarget(out rTarget as optional Widget) returns nothing binds to "<builtin>"
11701183
11711184public foreign handler MCWidgetEvalMyChildren(out rChildWidgets as List) returns nothing binds to "<builtin>"
@@ -1260,6 +1273,49 @@ end syntax
12601273
12611274//
12621275
1276+ /**
1277+ Summary: Returns the current widget.
1278+ Returns: A widget object.
1279+
1280+ Example:
1281+
1282+ -- In a widget
1283+ private variable mSelf as Widget
1284+ public handler OnCreate() returns nothing
1285+ -- Keep a reference to this widget
1286+ put this widget into mSelf
1287+
1288+ -- defined in separate module library
1289+ SetEventCallback(EventCallback)
1290+ end handler
1291+
1292+ -- may be called from another module library
1293+ private handler EventCallback() returns nothing
1294+ -- update internal variables
1295+
1296+ -- notify ide of changes
1297+ trigger all in mSelf
1298+ end handler
1299+
1300+ Description:
1301+ This widget evaluates to the current widget. This can be used to retain a
1302+ reference for occasions where widget handlers may be called from another module,
1303+ where the current widget may not be valid.
1304+
1305+ This is useful when LCB handlers within a widget module are used as
1306+ asynchronous callback functions passed to foreign functions, as these may be
1307+ called at a time when the widget is not the currently active widget. Using the
1308+ reference prevents updates being seen as coming from the wrong widget.
1309+ */
1310+
1311+ syntax ThisWidget is expression
1312+ "this" "widget"
1313+ begin
1314+ MCWidgetEvalThisWidget(output)
1315+ end syntax
1316+
1317+ //
1318+
12631319/**
12641320Summary: The currently placed child widgets of this widget.
12651321Returns: A list of the child widgets of this widget.
0 commit comments