#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include "globals.h"
Functions | |
int | mt_ObjcAttach (APPvar *app, int mode, WINDOW *win, int index, int type,...) |
Attach a variable or a callback function at an object. |
Attach a variable or a callback function at an object.
app | application descriptor, | |
mode | destination type
| |
win | targeted window or NULL, | |
index | object index to attach, | |
type | type of binding
| |
... | variable argument list depending on value of type parameter. With BIND_VAR and BIND_BIT, argument is a pointer to the (integer) variable to bind. BIND_BIT requires a second parameter which is the bit to bind. BIND_VAR requires a second parameter which is the value of the variable when the object is selected. With BIND_FUNC, argument is a pointer to the function and a second optional argument is a pointer to a user data which will given to the function (see examples). |
With formulars or toolbars, only EXIT or TOUCHEXIT objects can be attached at a callback function. When the user selects these objects, the callback function is invoked. Only SELECTABLE objects can be binded to a variable When the user selects these objects, the variable is set to its "value_when_selected" value. Only SELECTABLE objects can be binded to a bitset. When the user selects these objects, the bit of the variable is set. If such object is unselected, then the bit is cleared. Please note that all these rules also appli for RADIO button (the variable is no more filled with the index of the selected object).
With menu, an item of the menu can be attached at a function or at a bitset. When an item is linked to a bitset, it is checked or unchecked when the user selects it. The variable linked is filled with 1 or 0 (or a specific bit with the BIND_BIT mode) when the item is checked or unchecked. Notice desktop menu is addressed if win parameter is set to NULL.
A function linked to a menu object has an additionnal parameter - title - which indicated the menu title index selected. This parameter is required by mt_MenuTNormal():
The fifth parameter data is an optional user pointer data specified by mt_ObjcAttach().It's highly recommended to use specialized ObjcAttachXxx() functions instead of this general function. They are:
static int radio = 1; #define OPTION1 0x1 // bit 0 #define OPTION2 0x2 // bit 1 #define OPTION3 0x4 // bit 2 static int options = 0; { // Before : create the form with FormCreate() // Then attach the objects // 3 radio buttons in a formular // the variable "radio" will contain either 1, 2 or 3 // depending on the selected radio button ObjcAttachVar( OC_FORM, win, RAD1, &radio, 1); ObjcAttachVar( OC_FORM, win, RAD2, &radio, 2); ObjcAttachVar( OC_FORM, win, RAD3, &radio, 3); // some checkboxes ... ObjcAttachBit( OC_FORM, win, BUT1, &options, OPTION1); ObjcAttachBit( OC_FORM, win, BUT2, &options, OPTION2); ObjcAttachBit( OC_FORM, win, BUT3, &options, OPTION3); // An example of function linked to an object // see after for the definition of the function ObjcAttachFormFunc( win, OK, ButOk, "a dummy data"); } // Function linked to OK object void ButOk( WINDOW *win, int index, int mode, char *mydata) { // Unselect the object ... ObjcChange( mode, win, index, NORMAL, 0); puts( mydata); // Should print 'a dummy data' ... // ... and destroy the window ApplWrite( app.id, WM_DESTROY, win->handle); }