EZ
Up Prev Next Contents


1.10.10 Example 9, The Dialogue Again

In example 8, when you click on the Press me button, it pops up the dialogue. Depending on the location dialogue, the input focus may or may not be on the dialogue.

In this example, we modify example 8 a little bit so that when the dialogue pops up, the input focus is set to the No button on the dialogue. If the user press Button1 immediately without moving the pointer, the no button will be activated. The user can also activate the no button by hitting the space-bar or the return key.

/************************** Example 9 ***********************/
#include "EZ.h"

void yesCallBack(EZ_Widget *widget, void *data)
{
  EZ_Shutdown();
  exit(0);
}

void noCallBack(EZ_Widget *widget, void *data)
{
  if(widget)
    {
      EZ_Widget *toplevel = (EZ_Widget *)data;

      EZ_HideWidget(toplevel); 
      EZ_ReleaseGrab();
    }
}

void buttonCallBack(EZ_Widget *widget, void *data)
{
  static EZ_Widget *dialogue = NULL;

  if(dialogue == NULL)
    {
      EZ_Widget *yes, *no;

      dialogue = EZ_CreateWidget(EZ_WIDGET_FRAME, NULL,
                                 EZ_LABEL_STRING, "Want to Quit?",
                                 EZ_TRANSIENT, 1, 0);
      yes = EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON,dialogue,
                            EZ_LABEL_STRING, "Yes", 0);
      no  = EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON,dialogue,
                            EZ_LABEL_STRING, "No", 0);
      EZ_AddWidgetCallBack(yes, EZ_CALLBACK, yesCallBack, NULL, 0);
      EZ_AddWidgetCallBack(no, EZ_CALLBACK, noCallBack, dialogue, 0);
      EZ_SetWidgetPtrData(dialogue, no);  /* rember 'no' button */
    }
  EZ_DisplayWidget(dialogue);
  EZ_SetGrab(dialogue); 
  EZ_SetFocusTo((EZ_Widget *)EZ_GetWidgetPtrData(dialogue));
}

main(int argc, char **argv)
{
  EZ_Widget *frame, *button, *buttonA;

  EZ_Initialize(argc,argv,0); 
  frame = EZ_CreateWidget(EZ_WIDGET_FRAME, NULL, 0);
  button  = EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON, frame, 
                            EZ_LABEL_STRING, "Press me", 
                            0);
  EZ_AddWidgetCallBack(button, EZ_CALLBACK, buttonCallBack, NULL,0);
  buttonA = EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON, frame,
                            EZ_LABEL_STRING, "A Button",
                            0);
  EZ_DisplayWidget(frame);
  EZ_EventMainLoop();
}
/************************** Example 9 ***********************/


HTML Documentation Maintainance:Arturo Espinosa <arturo@nuclecu.unam.mx>