objc_attach.c File Reference

#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "globals.h"

Functions

int mt_ObjcAttach (APPvar *app, int mode, WINDOW *win, int ob, int type,...)
 Attach a variable or a callback function at an object.

Function Documentation

int mt_ObjcAttach APPvar app,
int  mode,
WINDOW win,
int  ob,
int  type,
  ...
 

Attach a variable or a callback function at an object.

Parameters:
app application descriptor,
mode destination type
  • OC_FORM if the object is in a window formular,
  • OC_TOOLBAR object is in a toolbar,
  • OC_MENU object is in a window menu,
win targeted window or NULL,
ob object index to attach,
type type of binding
  • BIND_VAR attach a variable,
  • BIND_BIT attach a specific bit of a variable,
  • BIND_FUNC attach a function,
... 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).
Returns:
0 or a negative code error.
mt_ObjcAttach() attaches a function or a variable at an object from a window formular, a toolbar or a menu. The rules are differents if you use a formular and a toolbar or a menu.

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.

Callback function prototype
A function linked with to an object in a formular or a toolbar has the following interface:
  void __CDECL func ( APPvar *ap, WINDOW *win, int ob, int mode, void *data);
where win is the host window, ob is the index of the attached object and mode can be OC_FORM, OC_TOOLBAR or OC_MENU. If an user data pointer is specified with ObjcAttach(), this pointer can be read as a fourth parameter of the binded function (data in our example).

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():

  void __CDECL func ( APPvar *ap, WINDOW *win, int ob, int mode, int title, void *data);
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:

  • mt_ObjcAttachVar() similar to mt_ObjcAttach(...,BIND_VAR,...)
  • mt_ObjcAttachBit() similar to mt_ObjcAttac(...,BIND_BIT,...)
  • mt_ObjcAttachFormFunc() similar to mt_ObjcAttach(OC_FORM,...,BIND_FUNC,...)
  • mt_ObjcAttachTBFunc() similar to mt_ObjcAttach(OC_TOOLBAR,...,BIND_FUNC,...)
  • mt_ObjcAttachMenuFunc() similar to mt_ObjcAttach(OC_MENU,...,BIND_FUNC,...)

Examples
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 ob, int mode, char *mydata) {
  // Unselect the object ... 
  ObjcChange( mode, win, ob, NORMAL, 0);
  puts( mydata); // Should print 'a dummy data' ...
  // ... and destroy the window
  ApplWrite( app.id, WM_DESTROY, win->handle);
}


Generated on Thu Jun 22 11:45:27 2006 for WinDom by  doxygen 1.4.6