PtCallbackInfo

PtCallbackInfo — gives access to callback information.

Synopsis

class PtCallbackInfo
{
    event;                     // PhEvent
    reason;                    // unsigned long
    reason_subtype;            // unsigned long

// one from the following group, depending on the widget:

    basic;                     // PtBasicCallback
    calendar;                  // PtCalendarSelectCallback
    clock_time;                // PtClockTimeCallback
    container;                 // PtContainerCallback
    divider;                   // PtDividerCallback
    filesel;                   // PtFileSelCallback
    filesel_bkgd;              // PtFileSelBkgdCallback
    font_name;                 // string 
    gen_tree_input;            // PtGenTreeInput
    graphic;                   // PhArea 
    hotkey;                    // PtHotkeyCallback
    html;                      // PtHtmlCallback
    list;                      // PtListCallback
    list_input;                // PtListInput
    matrix;                    // CwMatrixCallback
    numeric_float;             // PtNumericFloatCallback
    numeric_integer;           // PtNumericIntegerCallback
    on_off_button;             // PtOnOffButtonCallback
    rtmeter;                   // RtMeterCallback
    scrollbar;                 // PtScrollbarCallback
    slider;                    // PtSliderCallback
    terminal_font_change;      // PtTerminalFontChange
    terminal_input;            // PtTerminalInput
    terminal_option_change;    // PtTerminalOptionChange
    terminal_scrlbk_cb;        // PtTerminalScrlbkCb
    terminal_size_change;      // PtTerminalSizeChange
    text;                      // PtTextCallback
    tree;                      // PtTreeCallback
    tty_output;                // PtTtyOutput
}
		

Description

This class gives access to callback information. It has three normal instance variables, and a group of widget-specific instance variables that correspond to one or more widgets in Gamma.

Whenever a callback is generated, a locally-scoped instance of PtCallbackInfo, called cbinfo, is created. It has the three regular instance variables, as well as one instance variable from the widget-specific group. You can access these callback variables using dot notation.

[Important]

Only one of the instance variables from the group of widget-specific instance variables should be used: the one that actually corresponds to the widget. Using an instance variable that doesn't correspond to the widget will give unpredictable results.

Instance Variables

event

A PhEvent that caused the generation of the callback.

reason

The value of the callback that was generated.

reason_subtype

The value corresponding to the way the callback was generated, if more than one way was possible. The possibilities are callback-specific, and are documented in detail with the relevant widget in the Photon documentation.

Widget-Specific Instance Variables

Most of the instance variables from the widget-specific group have a callback class associated with them, and they are documented with that class. Those that don't are documented here.

font_name

A string comprising the name of the new font. This information comes from the Pt_CB_FONT_MODIFY callback, generated by PtFontSel. Also see Pt_CB_FONT_MODIFY in the PtFontSel section of the Photon documentation.

graphic

A PhArea indicating the previous dimensions of the graphic. This information comes from the Pt_CB_RESCALE callback, which is generated when a PtGraphic is rescaled. Also see Pt_CB_RESCALE in the PtGraphic section of the Photon documentation.

Examples

This example, ex_Raw.g, is included in the product distribution.

#!/usr/cogent/bin/phgamma


/*
 * This example demonstrates how to access raw callback information.
 */


Ph_EV_PTR_STEADY := 2;
Ph_EV_PTR_UNSTEADY := 3;

function main ()
{
  require_lisp("PhotonWidgets.lsp");
  PtInit (nil);

  w = new (PtWindow);
  w.SetArea(100, 100, 120, 80);
  b = new (PtButton);
  b.SetPos(30, 30);
  b.text_string = "Test Area";
  
  PtAttachCallback (b, Pt_CB_RAW, #cbBoundary(), Ph_EV_BOUNDARY);
  PtRealizeWidget (w);
  
  PtMainLoop();
}

/* widget, cbinfo, event_data are all available here */
function cbBoundary ()
{
	local		event;

	event = cbinfo.event;

	if (event.subtype == Ph_EV_PTR_ENTER)
		princ ("Enter\n");
	else if (event.subtype == Ph_EV_PTR_LEAVE)
		princ ("Leave\n");
	else if (event.subtype == Ph_EV_PTR_STEADY)
		princ ("Steady\n");
	else if (event.subtype == Ph_EV_PTR_UNSTEADY)
		princ ("Unsteady\n");
	else 
		princ ("unexpected event subtype\n");
}

This example, ex_PtCallbackInfo.g, is included in the product distribution.

#!/usr/cogent/bin/phgamma

/*
 * This example demonstrates how to get information from a callback,
 * the PtCalendarSelectCallback in this case.  The first three
 * callback functions print the regular instance variables.  The next
 * callback function prints the PtCalendarSelectCallback instance
 * variable named date.  Then the instance variables of date are
 * printed by the next three callback functions. The last two
 * callback functions print the remaining two variables of
 * PtCalendarSelect.
 */

require_lisp("PhotonWidgets.lsp");
PtInit(nil);

win = new(PtWindow);
win.SetPos (300,0);

cal = new(PtCalendar);
cal.SetDim(200,200);
cal.fill_color = 0x88ddbb;

PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #pretty_princ("Event: ",cbinfo.event,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Reason: ",cbinfo.reason,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Subtype: ",cbinfo.reason_subtype,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Day: ",cbinfo.calendar.date.day + 1,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Month: ",cbinfo.calendar.date.month + 1,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Year: ",cbinfo.calendar.date.year,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                 #princ("Time: ",cbinfo.calendar.time,"\n"));
PtAttachCallback(cal,Pt_CB_CALENDAR_SELECT,
                #princ("Type: ",cbinfo.calendar.type,"\n\n"));

princ(Pt_CB_CALENDAR_SELECT);
		
PtRealizeWidget(win);
PtMainLoop();

See Also

PtAttachCallback