PtContainerGiveFocus

PtContainerGiveFocus — gives focus to a widget.

Syntax

PtContainerGiveFocus (widget, event)

		

Arguments

widget

A container-type widget.

event

The event to pass to both the object losing focus and the widget gaining focus.

Returns

t if successful.

Description

This function gives focus to the widget. The event argument is used to pass a known event to both the object losing focus and the widget, which is gaining focus. If the event is not important to you, pass a new instance of the PhEvent class.

Example

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

#!/usr/cogent/bin/phgamma

/*
This example puts up a window with 10 button widgets.  The focus is
moved through the buttons by a timer calling the change_focus()
function every 0.2 sec.  The appearance of the buttons (a rendered
focus) changes when they receive focus.
*/

require_lisp("PhotonWidgets.lsp");
PtInit(nil);
win = new(PtWindow);

max = 10;
button_array = make_array(0);
for(i=0;i<max;i++)
{
  button_array[i] = new(PtButton);
  button_array[i].text_string = string("But",i);
  button_array[i].SetPos((i % 5) * 35, div(i,5) * 30);
  PtRealizeWidget(button_array[i]);
}
PtRealizeWidget(win);

current_focus = 0;
function change_focus ()
{
  PtContainerGiveFocus(button_array[current_focus],new(PhEvent));
  current_focus = (current_focus + 1) % max;
}

every(0.2,#change_focus());
PtMainLoop();

See Also

In Photon documentation: PtContainerGiveFocus.