GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
% This file was created automatically from usercomm.msk.1% DO NOT EDIT!2\Chapter{User Communication}34{\XGAP} has two main means to communicate with the user. The first is the5normal command processing: The user types commands, they are transmitted to6{\GAP}, are executed, and produce output, which is displayed in the command7window. The second is the mouse and the other parts of the graphical user8interface. This latter part can be divided into menus, mouse events,9dialogs, and popups.1011\beginitems12Menus & Most of the windows of {\XGAP} have menus. The user can select13entries in them and this information is transformed to a function call in14{\GAP}. Menu entries can be checked or not, so menus can also display15information.1617Mouse Events & A mouse event is the pressing or releasing of a mouse18button, together with the position where the mouse pointer is in the exact19moment this happens and the state of certain keyboard keys (mainly shift20and control). Such events also trigger {\GAP} function calls and the21corresponding functions can react on these events and for example wait for22others.2324Dialogs & Dialogs are windows which display information and into which25the user can enter information for example in form of text fields.2627Popups & Popups are special dialogs where the user can not type text but28can only click on certain buttons. {\XGAP} has so called ``text selectors''29which are a convenient construct to display textual information and let the30user select parts of it.31\enditems3233Most of those graphical objects have corresponding {\GAP} objects, which34are created by constructors and can be used later on by operations.353637%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%38\Section{Menus in Graphic Sheets}3940\>`Menu( <sheet>, <title>, <ents>, <fncs> )'{Menu![menu]}@{`Menu'!`[menu]'} O41\>`Menu( <sheet>, <title>, <zipped> )'{Menu![menu]}@{`Menu'!`[menu]'} O4243`Menu' returns a pulldown menu. It is attached to the sheet <sheet>44under the title <title>. In the first form <ents> is a list of strings45consisting of the names of the menu entries. <fncs> is a list of46functions. They are called when the corresponding menu entry is selected47by the user. The parameters they get are the graphic sheet as first48parameter, the menu object as second, and the name of the selected entry49as third parameter. In the second form the entry names and functions are50all in one list <zipped> in alternating order, meaning first a menu entry,51then the corresponding function and so on.52Note that you can delete menus but it is not possible to modify them,53once they are attached to the sheet.54If a name of a menu entry begins with a minus sign or the list entry55in <ents> is not bound, a dummy menu entry is generated, which can sort56the menu entries within a menu in blocks. The corresponding function57does not matter.585960\>Check( <menu>, <entry>, <flag> ) O6162Modifies the ``checked'' state of a menu entry. This is visualized by a63small check mark behind the menu entry. <menu> must be a menu object,64<entry> the string exactly as in the definition of the menu, and <flag>65a boolean value.666768\>Enable( <menu>, <entry>, <flag> ) O69\>Enable( <menu>, <boollist> ) O7071Modifies the ``enabled'' state of a menu entries. Only enabled menu entries72can be selected by the user. Disabled menu entries are visualized73by grey or shaded letters in the menu. <menu> must be a menu object,74<entry> the string exactly as in the definition of the menu, and <flag>75a boolean value. <entry> can also be a natural number meaning the index76of the corresponding menu entry.77In the second form <boollist> must be a list where each78entry has either a boolean value or the value `fail'79The list must be as long as the80number of menu entries in the menu <menu>. All menu entries where a81boolean value is provided are enabled or disabled according to this82value.83848586See the explanation of `GraphicSheet' ("Close!Callback") for the ``Close''87event, which occurs when the user selects the menu entry88`close graphic sheet' in the `Sheet' menu.8990%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%91\Section{Mouse Events}9293When a mouse event occurs, this is communicated to {\GAP} via a function94call which in turn triggers a callback. As described in "GraphicSheet" to95"CtrlRightPBDown" the following callback keys are predefined as reactions96on mouse events: `LeftPBDown', `RightPBDown', `ShiftLeftPBDown',97`ShiftRightPBDown', `CtrlLeftPBDown', `CtrlRightPBDown'.9899Note that when your function gets called, the mouse button will still be100pressed. So it can react and for example wait for the release. There is an101easy way to find out about the state of the mouse buttons after the event:102103\>WcQueryPointer( <id> ) F104105<id> must be a `WindowId' of an {\XGAP} sheet. This function returns a106vector of four integers. The first two are the coordinates of the mouse107pointer relative to the {\XGAP} sheet. Values outside the window are108represented by $-1$. The third element is a number where the pressed109buttons are coded. If no mouse button is pressed, the value is zero.110`BUTTONS.left' is added to the value, if the left mouse button is pressed111and `BUTTONS.right' is added, if the right mouse button is pressed. The112fourth value codes the state of the shift and control. Here the values113`BUTTONS.shift' and `BUTTONS.ctrl' are used.114115116117This function is used in118119\>Drag( <sheet>, <x>, <y>, <bt>, <func> ) O120121Call this function when a button event has occurred, so the button <bt>122is still pressed. It waits until the user releases the mouse button and123calls <func> for every change of the mouse position with the new x and124y position as two integer parameters. You can implement a dragging125procedure in this way as in the following example: (we assume that a126`LeftPBDown' event just occurred and x and y contain the current mouse127pointer position):128129\begintt130storex := x;131storey := y;132box := Rectangle(sheet,x,y,0,0);133if Drag(sheet,x,y,BUTTONS.left,134function(x,y)135local bx,by,bw,bh;136if x < storex then137bx := x;138bw := storex - x;139else140bx := storex;141bw := x - storex;142fi;143if y < storey then144by := y;145bh := storey - y;146else147by := storey;148bh := y - storey;149fi;150if bx <> box!.x or by <> box!.y then151Move(box,bx,by);152fi;153if bw <> box!.w or bh <> box!.h then154Reshape(box,bw,bh);155fi;156end) then157the box had at one time at least a certain size158... work with box ...159else160the box was never big enough, we do nothing161fi;162Delete(box);163\endtt164165166167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%168\Section{Dialogs}169170\>Dialog( <type>, <text> ) O171172creates a dialog box and returns a {\GAP} object describing it. There are173currently two types of dialogs: A file selector dialog (called174`Filename') and a dialog type called `OKcancel'. <text> is a text that175appears as a title in the dialog box.176177178179\>Query( <obj> ) O180\>Query( <obj>, <default> ) O181182Puts a dialog on screen. Returns `false' if the user clicks ``Cancel'' and183a string value or filename, if the user clicks ``OK'', depending on the184type of dialog. <default> is an optional initialization value for the185string.186187188189%Puts a dialog on screen. Returns `false' if the user clicks ``Cancel'' and190%a string value or filename, if the user clicks ``OK'', depending on the191%type of dialog. <default> is an optional initialization value for the string.192193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%194\Section{Popups}195196\>PopupMenu( <name>, <labels> ) O197198creates a new popup menu and returns a {\GAP} object describing it.199<name> is the title of the menu and <labels> is a list of strings for200the entries. Use `Query' to actually put the popup on the screen.201202203204\>`Query'{Query!for popup}@{`Query'!for popup}205206actually puts a popup on screen. `Query' returns the string of the207selected entry or `false' if the user clicks outside the popup.208See also `Query' for dialogs in "Query".209210\>TextSelector( <name>, <list>, <buttons> ) O211212creates a new text selector and returns a {\GAP} object describing it.213<name> is a title. <list> is an alternating list of strings and214functions. The strings are displayed and can be selected by the user.215If this happens the corresponding function is called with two216parameters. The first is the text selector object itself, the second217the string that is selected. A selected string is highlighted and all218other strings are reset at the same time. Use `Reset' to reset all219entries.220221<buttons> is an analogous list for the buttons that are222displayed at the bottom of the text selector. The text selector is223displayed immediately and stays on screen until it is closed (use the224`Close' operation). Buttons can be enabled and disabled by the `Enable'225operation and the string of a text can be changed via `Relabel'.226227228229\>Enable( <sel>,<bt>,<flag> )!{for text selectors}230\>Enable( <sel>,<btindex>,<flag> )!{for text selectors}231232Enables or disables the button <bt> (string value) or <btindex>233(integer index) of the text selector <sel>, according to <flag>.234235\>Relabel( <sel>, <list> )!{for text selectors}236\>Relabel( <sel>, <index>, <text> )!{for text selectors}237238Changes the strings that are displayed in the text selector. In the239first form <list> must be a list of strings. The second form only240changes the text at index <index>.241242\>SetName( <sel>, <index>, <string> )!{for text selectors}243244Every string in a text selector has a name. The names are stored in245the list `names' component of the text selector. So `sel!.names' ist a246list containing the names. The names are initialized with the strings247from the creation of the text selector.248249\>Reset( <sel> )!{for text selectors}250251Resets all strings of a text selector, such that they are no longer252selected.253254\>Close( <sel> )!{for text selectors}255256Closes a text selector. It vanishes from screen.257258Note that you have access to the indices and names of strings and259buttons:260261\>`IndexOfSelectedText'{IndexOfSelectedText}@{`IndexOfSelectedText'}262263Whenever the user clicks on a text in a text selector, the global264variable is set to the index of the text in the text265selector.266267\>`IndexOfSelectedButton'{IndexOfSelectedButton}@{`IndexOfSelectedButton'}268269Whenever the user clicks on a button in a text selector, the global270variable is set to the index of the button in the text selector.271272273