### 2.9.8 Example 8, A Dialogue

Here is an example that uses `EZ_SetGrab` to implement a dialogue box.

We create a frame with two buttons. One button is associated with a dialogue box. When pressed, it posts the dialogue and sets a grab on the dialogue.

The dialogue box contains two buttons. `Yes` and `No`. When the `No` button is pressed, it hides the dialogue and hence release the grab.

During the period when the dialogue is viewable, event processing for other widgets, except descendants of the dialogue, are suspended.

    /************************** Example 8 ***********************/
    #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;

          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_DisplayWidget(dialogue);
      EZ_SetGrab(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 8 ***********************/

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