DIRECTORY Rope, ViewerClasses, EBTypes; EmbeddedButtons: CEDAR DEFINITIONS = BEGIN ActiveButton: TYPE = EBTypes.ActiveButton; ActiveDoc: TYPE = EBTypes.ActiveDoc; ButtonInfo: TYPE = EBTypes.ButtonInfo; EBLanguageProc: TYPE = EBTypes.EBLanguageProc; ROPE: TYPE = Rope.ROPE; Viewer: TYPE = ViewerClasses.Viewer; Error: PROC [screenMessage: ROPE, fileMessage: ROPE ¬ NIL]; NotifyProc: TYPE = PROC [buttonInfo: ButtonInfo, events: LIST OF REF ANY, targetViewer: Viewer, applicationData: REF] RETURNS [result: REF ¬ NIL]; RegisteredNotifyProc: TYPE = PROC [events: LIST OF REF ANY, buttonInfo: ButtonInfo] RETURNS [result: REF ¬ NIL]; LinkDocToApplication: PROC [doc: ActiveDoc, target: ATOM, targetViewer: Viewer ¬ NIL, applicationData: REF ¬ NIL, notifyProc: NotifyProc ¬ NIL]; RegisterApplication: PROC [target: ATOM, notifyProc: RegisteredNotifyProc]; RegisterPoppyProc: PROC [procedureName: ATOM, proc: EBLanguageProc, interpreted: BOOL ¬ TRUE]; PassEventToApplication: PROC[event: LIST OF REF ANY, buttonInfo: ButtonInfo, application: ATOM ¬ $MessageHandlers]; GetApplications: PROC[buttonInfo: ButtonInfo] RETURNS [applications: LIST OF ATOM]; GetFieldRope: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [rope: ROPE]; GetFieldAtom: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [atom: ATOM]; GetFieldRef: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [ref: REF]; SetFieldRope: PROC [key: ATOM, rope: ROPE, buttonInfo: ButtonInfo]; SetFieldAtom: PROC [key: ATOM, atom: ATOM, buttonInfo: ButtonInfo]; SetFieldRef: PROC [key: ATOM, ref: REF, buttonInfo: ButtonInfo]; GetButtonClass: PROC [buttonInfo: ButtonInfo] RETURNS [REF]; GetButtonName: PROC [buttonInfo: ButtonInfo] RETURNS [name: ATOM]; GetAtom: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [atom: ATOM]; SetAtom: PROC [key: ATOM, atom: ATOM, buttonInfo: ButtonInfo, edited: BOOL]; GetRope: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [rope: ROPE]; SetRope: PROC [key: ATOM, rope: ROPE, buttonInfo: ButtonInfo, edited: BOOL]; GetRef: PROC [key: ATOM, buttonInfo: ButtonInfo] RETURNS [ref: REF]; SetRef: PROC [key: ATOM, ref: REF, buttonInfo: ButtonInfo, edited: BOOL]; GetText: PROC [buttonInfo: ButtonInfo] RETURNS [text: ROPE]; GetDocName: PROC [buttonInfo: ButtonInfo] RETURNS [name: ROPE]; LookUpActiveDoc: PROC [viewer: Viewer] RETURNS [doc: ActiveDoc]; FeedbackNotify: PROC [feedbackEvent: LIST OF REF ANY, buttonInfo: ButtonInfo]; InButton: PROC [x, y: INTEGER, buttonInfo: ButtonInfo] RETURNS[BOOL]; EachButtonProc: TYPE = PROC [button: ActiveButton, doc: ActiveDoc] RETURNS [done: BOOL ¬ FALSE]; MapButtons: PROC [doc: ActiveDoc, proc: EachButtonProc] RETURNS [aborted: BOOL ¬ FALSE]; CheckDoc: PROC [doc: ActiveDoc]; GetButtonValue: PROC [buttonInfo: ButtonInfo, variable: ATOM ¬ $Value] RETURNS [value: REF]; SetButtonValue: PROC [buttonInfo: ButtonInfo, variable: ATOM ¬ $Value, value: REF]; RegisterNameValuePair: PROC [name: ATOM, value: REF, buttonInfo: ButtonInfo]; GetValue: PROC [name: ATOM, doc: ActiveDoc, variable: ATOM ¬ $Value] RETURNS [val: REF]; SetValue: PROC [name: ATOM, val: REF, doc: ActiveDoc, variable: ATOM ¬ $Value]; END. #˜ EmbeddedButtons.mesa Copyright Ó 1988, 1989, 1990, 1992 by Xerox Corporation. All rights reserved. Goodisman, August 13, 1989 8:31:37 pm PDT Bier, February 19, 1990 10:50 am PST Kenneth A. Pier, October 30, 1990 5:01 pm PST Doug Wyatt, April 15, 1992 2:49 pm PDT Contents: Includes routines used by applications that provide functionality for embedded buttons or that use an active document as a control panel and routines for accessing button properties. Introduction How Button Presses are Handled When an editor receives an event aimed at an active button, it passes input handling control to the EmbeddedButtons package by calling HandleEvent. EmbeddedButtons determines the class of the button and passes the event to the button class. When a button class has parsed an input action into a message for an application, it passes the message to the application by calling PassEventToApplication. To register an application with EmbeddedButtons, use the EBApplications interface. Making Buttons The on-disk representation of a ButtonData property is a text string, in the Poppy Language. The Poppy language defines a set of named fields, each of which can have a single name as its value, or a list of values enclosed in parentheses. For instance, here is a Poppy string representing a pop-up button: Poppy1 Class: PopUpButton MessageHandler: Tioga Menu: ( ((1 ApplyLook) "Make Bold" "Makes the selected Tioga text bold") ((8 ApplyLook) "Make Italic" "Makes the selected Tioga text italic") ((ClearLooks) "Clear Looks" "Removes all looks from the selected Tioga text") ) Error Reporting Applications How to make an EmbeddedButtons application (1) To make an EmbeddedButtons application that is available from all active documents, simply register a new procedure by calling EBApplications.RegisterApplication (see below). (2) To use an active document as the control panel for a particular application, running in a particular window, link the window to the active document using LinkDocToApplication below. How EmbeddedButtons applications work An EmbeddedButtons application is a Cedar procedure of type NotifyProc (see below) that is called when a button is pressed. Each NotifyProc is given a short name to identify it. When this name is placed in the "MessageHandler" field of a button, all messages from that button will cause this Cedar procedure to be called. The Cedar procedure also receives a set of arguments. (1) The "buttonInfo" argument describes the button that was pressed and the document that the button is in. Usually, this argument can be ignored. (2) The "events" argument comes from the button itself, describing that entry in the "Menu" or "UpClickMessage" fields that was triggered by the current button click. Often application procedures will use these arguments to parameterize their behavior. (3) The targetViewer describes the viewer that the pressed button is linked to. This value will be NIL unless LinkDocToApplication has been performed on the active document containing this button. (4) The applicationData field contains that data that was provided by the LinkDocToApplication call, if any, that linked this document to an application. If this document is not acting as an application control panel, this field will be NIL. If the notify procedure for the named MessageHandler is NIL, then the regular notify procedure associated with the viewer to which the button is linked will be called with the viewer and the events as arguments. If the linked viewer is NIL, then the system checks the table of registered document links and calls the notify procedure found there if one exists. Example: This button *** has the following ButtonData property: ButtonData: Poppy1 Class: PopUpButton MessageHandler: Tioga Menu: ( ((1 ApplyLook) "Make Bold" "Makes the selected Tioga text bold") ((8 ApplyLook) "Make Italic" "Makes the selected Tioga text italic") ((ClearLooks) "Clear Looks" "Removes all looks from the selected Tioga text") ) Depending on which menu option the user choose, the registered NotifyProc named "Tioga," will be called with the events argument set to either LIST[^1 $ApplyLook], or LIST[^8, $ApplyLook], or LIST[$ClearLooks]. If result = $Error, the command triggered by the button failed with one or more errors. If result = $Warning, the command succeeded but produced one or more warnings. If result = NIL, the command either succeeded or nothing is known about how it did. Other return values may be used inthe future. Assigns the targetViewer, applicationData, and notifyProc to the target in the document. Registers the target ATOM as pointing to the notify proc of a particular application. Buttons in a document that is not linked to an application using LinkDocToApplication will send events to the RegisteredNotifyProc registered here if their ButtonTarget matches target. Registers a procedure that can be called from any statement written in the PoppyLisp sub-language. The procedure is called by enclosing the procedure name and its arguments in angle brackets <>. For example, the SetCursor routine is often called in Poppy feedback statements as: (MouseMotion ). Sends the event to the named registered application. If application = $MessageHandler, then a set of possible applications are tried: If the ButtonNotifyProcRuntime of the document is defined, send the events to it. If not, then if the target viewer of the document is defined, send the events to the notify procedure of the target viewer. If not, then attempt to send the events to the registered notify procedures from the button's MessageHandler: field. Returns the list of default applications that will receive poppy actions that are not explicitly sent using the command. If a MessageHandler field is provided, messages go to the applications listed in that field. If no application exists, GetApplications returns NIL. Access to Button Fields Getting and Setting the values of the Poppy fields stored in the button's ButtonData. Gets the rope corresponding to the key in the specification of the button. Gets the atom corresponding to the key in the specification of the button. Gets the ref corresponding to the key in the specification of the button. Sets the rope corresponding to the key in the specification of the button. Sets the atom corresponding to the key in the specification of the button. Sets the ref corresponding to the key in the specification of the button. Convenience routine. Equivalent to GetFieldRef[$Class, buttonInfo] followed by an EBEditors.ButtonDataFromRope, if needed. Convenience routine. Equivalent to GetFieldAtom[$Name, buttonInfo]. Makes sure that the fields have already been parsed. Access to Buttons as Document Elements Getting and setting properties Returns NIL if key not found. edited = FALSE specifies that the implementing editor should not consider this a change to the document. Returns NIL if key not found. edited = FALSE specifies that the implementing editor should not consider this a change to the document. Returns NIL if key not found. edited = FALSE specifies that the implementing editor should not consider this a change to the document. If the button is a textual document element, return the contents of the button as an ASCII string (throwing away any formatting). If the button is not a textual document element, return NIL. Returns the name of the doc. Often a filename or window name. Returns the active document that is associated with this viewer. Changing button appearance and other document properties Look up feedbackEvent in the Feedback: field of this button, and send to the editor the corresponding input event, which is hopefully a legal expression in the editor's input language. Allows applications to cause feedback in a button. FeedbackNotify is also called by button classes to cause feedback that results from events, such as state changes, that are not directly associated with user actions. Asks the editor which implements this button whether or not the supplied x and y coordinates fall within the button. Asks the editor which implements this document to call proc with each button in the document in which this button resides. aborted is TRUE if any proc returns done. Button Values Go through the given active document looking for potential problems with its buttons. Prints out the results on the EmbeddedButtons typescript. Returns the value of the named variable in this button. Set the value of the named variable in this button. Called by a button class to store a name and value pair in the document in which this button resides and to associate the button with the name. Returns the value of the variable "variable" that is included in the button (or group of buttons) of doc whose "Name" field contains "name". If several buttons of the same name have this field, returns one of them (use CheckDoc to find inconsistencies). Usually fast. Sets the value of the variable named in every button whose "Name" field contains "key" in the doc. Potentially slow. Ê×–(cedarcode) style•NewlineDelimiter ™codešœ™Kšœ ÏeœB™NKšœ)™)K™$K™-K™&—K˜KšÏnœ¹™ÁK™šÏk ˜ K˜—K˜šžœŸœŸ œŸ˜*K˜KšœŸœ˜*Kšœ Ÿœ˜$Kšœ Ÿœ˜&KšœŸœ˜.KšŸœŸœŸœ˜KšœŸœ˜$—head™ ™Iblockšœ™MšœR™R—™M™³Idisplay™•——™Kš žœŸœŸœŸœŸœ˜<—™ ™*Iitemšœ²™²Ošœ¹™¹—™%MšœÃ™ÃMšœ5™5Ošœ“™“Ošœý™ýOšœÅ™ÅOšœò™òMšœ8Ÿœ²Ÿœy™é—™M• CharPropsÞ Postfix-1.0 outlineBoxBearoff 1.0 outlineBoxThickness ButtonData‚Poppy1 Class: PopUpButton MessageHandler: Tioga Menu: ( ((1 ApplyLook) "Make Bold" "Makes the selected Tioga text bold") ((8 ApplyLook) "Make Italic" "Makes the selected Tioga text italic") ((ClearLooks) "Clear Looks" "Removes all looks from the selected Tioga text") )(šœ8™8Nšž œ—™¡MšœÒ™Ò—K˜Kšœ ŸœŸœ"ŸœŸœŸœŸœ)ŸœŸœ ŸœŸœ˜’šœŸœŸœ ŸœŸœŸœŸœŸœ ŸœŸœ˜pK™¬—K˜šžœŸœŸœŸœŸœŸœŸœ˜K™XK™—šžœŸœ Ÿœ$˜KKšœŸœö™K™—š žœŸœŸœ%ŸœŸœ˜^Kšœ¼™¼—K™šžœŸœŸœŸœŸœŸœ'Ÿœ˜sKšœ†™†K™ÄK™—š žœŸœŸœŸœŸœŸœ˜SKšœ•™•——™K™UK™š ž œŸœŸœŸœŸœ˜LK™JK™—š ž œŸœŸœŸœŸœ˜LKšœJ™JK™—š ž œŸœŸœŸœŸœ˜IKšœI™IK™—šž œŸœŸœŸœ˜CK™JK™—šž œŸœŸœŸœ˜CKšœJ™JK™—šž œŸœŸœŸœ˜@KšœI™IK™—šžœŸœŸœŸœ˜—šžœŸœŸœ˜@K™@K™—K™8K™š žœŸœŸœŸœŸœŸœ˜NKšœ”™”K™—š žœŸœŸœŸœŸœ˜EK™tK™—Kš œŸœŸœ(ŸœŸœŸœ˜`š ž œŸœ(Ÿœ ŸœŸœ˜XIoveršœ¥™¥——™ šžœŸœ˜ K™K™—š žœŸœ$Ÿœ Ÿœ Ÿœ˜\K™7K™—šžœŸœ$ŸœŸœ˜SK™3K™—šžœŸœŸœ Ÿœ˜MKšœ™K™—š žœŸœŸœŸœ ŸœŸœ˜XKšœ™K˜—š žœŸœŸœŸœŸœ ˜OK™}K™——KšŸœ˜—…— B7±