10.7. Photon only (in lib/photon.g)

These features have been added to Photon widgets to emulate GTK behavior.

10.7.1. Buttons - PtLabel.get_text, PtLabel.set_text

These two methods that get and set the text of a PtLabel are used to replicate similar methods in GTK.

   /*--------------------------------------------------------------------
    * Method:      PtLabel.get_text
    * Returns:     a string
    * Description: Emulates the GtkEntry.get_text() method, needed for
    *              the PtText widget, which is a child class of PtLabel.
    *              There is no need for an equivalent method in gtk.g.
    *------------------------------------------------------------------*/
   method PtLabel.get_text()
   {
     .text_string;
   }
   
   /*--------------------------------------------------------------------
    * Method:      PtLabel.set_text
    * Returns:     t or nil
    * Description: Emulates the GtkEntry.set_text() method, needed for
    *              the PtText widget, which is a child class of PtLabel.
    *              There is no need for an equivalent method in gtk.g.
    *------------------------------------------------------------------*/
   method PtLabel.set_text(str)
   {
     .text_string = str;
   }
   

10.7.2. Rollovers - PtBasic.rollover, attach_msg

The .rollover method lets us attach a rollover callback to any Photon widget. It checks to see if the pointer has entered or left the widget, and sends the appropriate message using the send_message function.

   /*--------------------------------------------------------------------
    * Method:      PtBasic.rollover
    * Returns:     t or nil
    * Description: Called by the attach_msg function to provide rollover
    *              functionality on any widget.  Used to send messages to
    *              the Controller when the pointer is on a button or other
    *              widget.
    *------------------------------------------------------------------*/
   method PtBasic.rollover(msg_in, msg_out)
   {
     if (cbinfo.event.subtype == Ph_EV_PTR_ENTER)
       send_message(msg_in);
     else if (cbinfo.event.subtype == Ph_EV_PTR_LEAVE)
       send_message(msg_out);
   }
   

The attach_msg function is a convenience function for attaching rollover callbacks on buttons. There is no built-in callback in Gamma/Photon for a Ph_EV_BOUNDARY event, so we use the Pt_CB_RAW callback to create one. The Pt_CB_RAW callback can be used in the format shown to attach a callback to any event. The event can be accessed by the cbinfo.event resource. In this case, the Ph_EV_BOUNDARY event has two subtypes, Ph_EV_PTR_ENTER and Ph_EV_PTR_LEAVE, which are accessed through the cbinfo.event.subtype resource, as in the PtBasic.rollover method shown above.

   /*--------------------------------------------------------------------
    * Function:    attach_msg
    * Returns:     t or nil
    * Description: Attaches a PtBasic.rollover demo library method to a widget
    *              boundary event.  Uses Pt_CB_RAW to access the Ph_EV_BOUNDARY
    *              event, since there is no callback associated with a
    *              Ph_EV_BOUNDARY event for a PtBasic widget.
    *------------------------------------------------------------------*/
   function attach_msg(widget, msg_in, msg_out)
   {
     PtAttachCallback (widget, Pt_CB_RAW,
                       `(@widget).rollover(@msg_in, @msg_out),
                       Ph_EV_BOUNDARY);
   }