Next: , Previous: , Up: Classes   [Index]


X11MessageBoxPane

X11MessageBoxPane Class

A X11MessageBoxPane object displays a popup window that contains a text message and a button that closes the window.

The button’s text is displayed by a X11LabelPane object, and the button is a X11ButtonObject. Generally, X11MessageBoxPane objects override any input to the program that opened them, so they contain their own event loop, in the show method.

Here is an example of a program that creates its own X11MessageBoxPane object, and then opens it when the user clicks on the main window’s button.


/* messagebox.ca - X11MessageBox Demonstration -*-c-*- */

#include <ctalk/ctalkdefs.h>

/* See the X11FreeTypeFont section of the the Ctalk reference. */
#define FTFONT_BOLD   200
#define FTFONT_MEDIUM 100

int main (void) {
  X11Pane new mainWindow;
  X11PaneDispatcher new dispatcher;
  X11ButtonPane new button;
  X11LabelPane new label;
  X11MessageBoxPane new messageBox;
  InputEvent new e;

  label textColor = "white";
  label canFocus = false;
  label borderWidth = 0;

  label ftFontVar initFontLib;
  label ftFontVar notifyLevel XFT_NOTIFY_NONE;

  mainWindow backgroundColor = "blue";
  label resources replaceAt "backgroundColor", "blue";
  button resources replaceAt "backgroundColor", "blue";
  messageBox resources replaceAt "backgroundColor", "blue";
  
  mainWindow initialize 255, 200;
  mainWindow inputStream eventMask = 
    EXPOSE|ENTERWINDOWNOTIFY|LEAVEWINDOWNOTIFY|BUTTONPRESS|BUTTONRELEASE|KEYPRESS|KEYRELEASE|WINDELETE|MOVENOTIFY;

  dispatcher attachTo mainWindow;
  button attachTo dispatcher, "125x75+c+100";
  label attachTo dispatcher, "177x80+34+15";
  messageBox attachTo dispatcher, "300x200";

  mainWindow map;
  mainWindow raiseWindow;

  mainWindow openEventStream;

  mainWindow setWMTitle "X11MessageBoxPane Demo";


  label multiLine "X11MessageBoxPane\nDemo";
  label resources replaceAt "textColor", "lightgray";
  label resources replaceAt "foregroundColor", "blue";
  label resources replaceAt "borderColor", "blue";

  button label multiLine "Open\nMessageBox";

  button label resources replaceAt "highlightForegroundColor", "gray80";

  /* Icon IDs, like ICON_INFO, are defined in ctalkdefs.h. */
  messageBox resources replaceAt "iconID", ICON_INFO;

  /* The program uses the "replaceAt" method because the key/value
     entry for "backgroundColor" the X11MessageBoxPane : new method
     has alread created an entry for backgroundColor. */
  messageBox resources replaceAt "backgroundColor", "blue";
  messageBox resources replaceAt "foregroundColor", "blue";
  messageBox resources replaceAt "messageText",
    	       "Hello, messageBox!\nYour message text here.";

  while (TRUE) {
    mainWindow inputStream queueInput;
    if (mainWindow inputStream eventPending) {
      e become mainWindow inputStream inputQueue unshift;

      mainWindow subPaneNotify e;

      switch (e eventClass value)
	{
	case EXPOSE:
	  button subPaneExpose (button, e);
	  label subPaneExpose (label, e);
	  break;
	case BUTTONRELEASE:
	  messageBox showManaged button;
	  break;
	case WINDELETE:
 	  mainWindow deleteAndClose;
	  exit (0);
	  break;
	}
    } else {
      usleep (1000);
    }
  }

}

Resources

background

The window’s background color, and the background color of the message label and the close button. The value is a String that contains a X11 named color. The default is ‘gray’. For a list of X11 color names, see showrgb(1).

buttonText

A String that contains the text that appears in the button. The default is ‘Ok’.

foregroundColor

A String with the name of the color that the messagebox window is filled with. The default is ‘gray’.

geometry

A String that contains the message window’s size, and, optionally, its position. The value is set to the dimensions that are given as arguments to the attachTo method.

iconID

An Integer that contains the identifier to the icon to be displayed. Ctalk defines the following constants for icons in ctalkdefs.h and in the graphics libraries.


ICON_NONE
ICON_CAUTION
ICON_INFO
ICON_QUESTION
ICON_STOP

The default is ‘ICON_NONE’, which causes no icon to be displayed. Any other constant causes an icon to be displayed to the left of the message text. The widget adjusts the size and position of the text automatically to provide space for the icon.

messageColor

A String that contains the color of the message text. The default is ‘black’. The message box sets the label’s textColor resource to this value.

messageFont

A String that contains the Fontconfig font descriptor. The default is ‘sans serif-12’. The pane uses this value to set the label’s ‘fcFont’ resource.

messageText

A String that contains the text of the message to be displayed. The default is ‘Sample message text.’.

pad

An Integer that contains the space in pixels betwween the button and label widgets, and between each widget and the edge of the window. The default is 10 pixels.

titleText

A String that contains the message window’s title text. The default is ‘Message’.

Instance Variables

button

A X11ButtonPane object that closes the window when clicked. The button’s default text is, ‘Ok’. Programs can change the text with a statement like the following, which changes the button’s text to, ‘Close’.


myMessageBox resources atPut "buttonText", "Close";

initialized

A Boolean that is true if the pane has already been initialized. When a message box is closed, it is not deleted - it is simply unmapped from the display. This variable is set to true so that the message box is initialized only once.

label

A X11LabelPane that displays the message box’s text. As configured, the label is the same color as the main message box window, and uses no borders. The label’s text is controlled by the resource, ‘messageText’. To set the message text, use a statement like the following.


myMessageBox resources atPut "messageText", "Today Is\nJanuary 3rd";

The class draws the label using multiline formatting, so if you want the text to appear on multiple lines, include the sequence ‘\n’ in the text (that’s a backslash and the character, ‘n’, not a literal newline).

keyState

An Integer which records whether the Tab or Enter keyboard shortcuts have been pressed. Pressing Tab highlights the pane’s button, and pressing Enter withdraws the pane’s window from the display, and the show method returns to the program that opened the message box.

mainWindowPtr

A Symbol that contains a pointer to the main window.

Instance Methods

attachTo (Object parentPane, String geometry)

Sets the message box’s dimensions and creates the object’s buffers and main window. Unlike other X11Pane subclasses, this method does not immediately attach the message box’s object to its parent pane, so the message box isn’t displayed until the program invokes the show or showManaged method.

draw (void)

Draws the label and button subpanes in the message box’s buffers and the buffers of the button and label subpanes. After calling this method, the refresh method makes the changes visible.

fill (String colorName)

A convenience method that fills the pane window with the color given as the argument.

initWidgets (void)

Initializes the message box’s button and label subpanes when the pane’s window is first opened. When constructed this method sets the initialized instance variable to ‘true’, so when the message box appears again, this method is a no-op.

new (String newPaneName)

The X11MessageBoxPane constructor.

refresh (void)

After the method draw renders the main window and the label and the button subwindow’s contents on the pane objects’ buffers, this method updates the visible window with the contents of the buffers.

show (void)

This method displays the message box, waits for events from the display system, and closes the message box when its button is clicked, then returns to the calling program.

show (X11ButtonPane buttonPane)

This method is similar to the show method, but it takes as its argument the pane object from the main window that caused the message window to open.

This method sets the main window’s button to be unclicked and then redrawn.

This method manages X11ButtonPane objects specifically, but it can be subclassed to manage any pane class object.

subPaneButton (Object subPane, InputEvent event)

This is the event handler for button press and button release events from the display hardware. When a button is clicked on, the message box draws the button in its clicked state. When the button is released, the pane draws the button unclicked, then unmaps the message box window from the display, and returns to the main program.

subPaneExpose (Object subPane, InputEvent event)

Handles drawing the message box when the program receives an Expose event from the display. This method calls the message box’s draw and refresh methods.

withdraw (void)

Unmaps the message box’s window from the display after the pane object receives a button release event while processing the show method. When the show or showManaged method receives the button release event, this method is called to remove the pane’s window from the display, and the show or showManaged method returns to the main program.


Next: , Previous: , Up: Classes   [Index]