PtMessage

Gamma/Photon: Using Gamma™ with the Photon microGUIŽ, Version 4.0
Prev |  | Next

# `PtMessage`

`PtMessage` -- A text message that appears in a pop-up window.

## Synopsis

    class PtMessage PtContainer
    {
        msg_button1;    // string  (Pt_ARG_MSG_BUTTON1)
        msg_button2;    // string  (Pt_ARG_MSG_BUTTON2)
        msg_button3;    // string  (Pt_ARG_MSG_BUTTON3)
        msg_default;    // short  (Pt_ARG_MSG_DEFAULT)
        msg_flags;      // flag  (Pt_ARG_MSG_FLAGS)
        msg_font;       // string  (Pt_ARG_MSG_FONT)
        msg_text;       // string  (Pt_ARG_MSG_TEXT)
        msg_title;      // string  (Pt_ARG_MSG_TITLE)
    }

## Base Classes

`PtWidget` <-- `PtBasic` <-- `PtContainer` <-- `PtMessage`

## Description

This widget is a pop-up window with a text message and up to three buttons for user input.

| For detailed information, please refer to PtMessage in the Photon documentation.

## Instance Variables

msg_button1,, msg_button2,, msg_button3,

  A string specifying the message label for each button. The default for `msg_button1` is "OK". The other two buttons have a default of nil, and will not be displayed unless this variable is assigned.

msg_default

  A number specifying which button is the default choice for the user. The text for this default button will be displayed in bold, and it will be activated if the user presses the Enter key.

msg_flags

  This instance variable has the following flag:

  Constant | Description
  --- | ---
  `Pt_MSG_CENTER_ON_PARENT` | Centers the message on its parent.

msg_font

  A string specifying the font of the message. Default is `"helv12"`.

msg_text

  A string comprising the text of the message.

msg_title

  A string comprising a title for the window. Default is `nil`.

## Callbacks

The following callbacks are associated with this widget:

Callback | Description
--- | ---
`Pt_CB_MSG_BUTTON1` | This callback is generated when button1 is pressed.
`Pt_CB_MSG_BUTTON2` | This callback is generated when button2 is pressed.
`Pt_CB_MSG_BUTTON3` | This callback is generated when button3 is pressed.

## Example

This example, `ex_PtModalStart.g`, is included in the `gamma_ph_`#`_examples_1_QNX4.tgz` file available on the Cogent Web Site. It demonstrates `PtModal` functions, but uses a `PtMessage` widget as well.

    #!/usr/cogent/bin/phgamma

    /*
    This example creates a window with a label you can drag, and a
    "Freeze" button.  Pressing the "Freeze" button initiates
    PtModalStart() and opens another window, with an "Unfreeze" button.
    Until the "Unfreeze" button is pressed, the first window is frozen.
    */

    require_lisp("PhotonWidgets");

    PtInit(nil);

    //The main window.

    win = new(PtWindow);
    win.SetArea(300,50,250,250);
    PtRealizeWidget(win);

    lab = new(PtLabel);
    lab.text_string = "Drag Me";
    lab.SetPos(90, 30);
    PtRealizeWidget(lab);

    button1 = new(PtButton);
    button1.text_string = "Freeze label and open message";
    button1.SetPos(30, 75);
    PtAttachCallback(button1, Pt_CB_ACTIVATE, #doOpen());
    PtRealizeWidget(button1);

    exitbut = new(PtButton);
    exitbut.SetPos(110, 175);
    exitbut.text_string = "Exit";
    PtAttachCallback(exitbut,Pt_CB_ACTIVATE,#exit_program(1));
    PtRealizeWidget(exitbut);

    //Functions to start and end modal state.

    function PhabModalLoop(done)
    {
    	local count = nil;
    	protect
    	{
    		count = PtModalStart();
    		while(!eval(done))
    			PtProcessEvent();
    	}
    	unwind
    	{
    		if(count != nil)
    			PtModalEnd(count);
    	}
    }

    function doOpen()
    {
      make_msg();
      done = nil;
      win.flags = Pt_BLOCKED;
      PhabModalLoop(eval(done));
    }

    function doClose()
    {
     done = t;
     win.flags = cons(Pt_BLOCKED, nil);
    }

    //The modal_state window.

    /* This function makes the modal_state window using a PtMessage widget.*/
    function make_msg()
    {
      win2 = new(PtMessage);
      win2.msg_text = "Press Cancel to continue.\nPress Print to print this\nmessage and continue.\n ";
      win2.msg_title = "The message.";
      win2.flags = Pt_MSG_CENTER_ON_PARENT;
      win2.msg_button1 = "Cancel";
      win2.msg_button2 = "Print";

      PtAttachCallback(win2, Pt_CB_MSG_BUTTON2, `princ(@win2.msg_text, "\n"));
      PtAttachCallback(win2, Pt_CB_MSG_BUTTON2, #doClose());
      PtAttachCallback(win2, Pt_CB_MSG_BUTTON1, #doClose());
      PtRealizeWidget(win2);
    }

    /*  An alternate way to make the window, using a PtWindow widget.
    	If used, the following lines must be added...
    	to doOpen()  :  PtRealizeWidget(win2);
    	to doClose() :  PtUnrealizeWidget(win2);
    	and the line :  make_msg();
    	should be removed from doOpen().

    win2 = new(PtWindow);
    win2.SetArea(440,100,100,80);
    lab2 = new(PtLabel);
    lab2.text_string = "Press button to continue.";
    button2 = new(PtButton);
    button2.text_string = "Unfreeze";
    button2.SetPos(40, 30);
    PtAttachCallback(button2, Pt_CB_ACTIVATE, #doClose());
    */

    //Functions to create a drag_able widget.

    DraggedWidget := nil;

    method PtWidget.StartDrag ()
    {
       DraggedWidget = self;
       PtInitDrag (self, nil, Ph_TRACK_DRAG | Ph_DRAG_TRACK);
    }

    function handle_drag ()
    {
       local   event = cbinfo.event, rect;

       if (event.type == Ph_EV_DRAG)
       {
          if (event.subtype == Ph_EV_DRAG_COMPLETE ||
                event.subtype == Ph_EV_DRAG_MOVE)
          {
             if (DraggedWidget)
             {
                rect = TranslateRect (event_data.drag_event.rect,
                  event.translation);
                DraggedWidget.SetPos (rect.ul.x, rect.ul.y);
             }
             if (event.subtype == Ph_EV_DRAG_COMPLETE)
                DraggedWidget = nil;
          }
       }
    }

    PtAttachCallback(win,Pt_CB_RAW,#handle_drag(),Ph_EV_DRAG);
    PtAttachCallback(lab,Pt_CB_RAW,#widget.StartDrag(),Ph_EV_BUT_PRESS);

    PtMainLoop();

Prev | Home | Next
`PtMenuLabel` | Up | `PtMultiText`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.