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


X11TextEntryBox

X11TextEntryBox Class

A X11TextEntryBox object pops up a dialog window that contains a X11TextEntryPane object, where the user can enter text. The contents of the text entry persist if the dialog window is re-opened, and the contents are available to the calling program, as is the text of the button and return code that indicates how the user closed the dialog box.

Here is an example program that demonstrates a X11TextEntryBox's use.


/* entrybox.ca, a X11TextEntryBox demonstration. -*-c-*- */

#include <ctalk/ctalkdefs.h>

int main (void) {
  X11Pane new mainWindow;
  X11PaneDispatcher new dispatcher;
  X11ButtonPane new button;
  X11LabelPane new label;
  X11TextEntryBox new textEntryBox;
  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";
  textEntryBox 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, "110x90+c+95";
  label attachTo dispatcher, "177x80+c+15";
  textEntryBox attachTo dispatcher, "300x200";

  mainWindow map;
  mainWindow raiseWindow;

  mainWindow openEventStream;

  mainWindow setWMTitle "X11TextEntryBox Demo";

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

  button label multiLine "Open\nText Entry\nDialog";

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

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

  button draw;
  button refresh;
  label draw;
  label refresh;

  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:
	  textEntryBox showManaged button;
	  printf ("returnVal: %d: %s: %s\n", textEntryBox returnVal,
		  textEntryBox returnText, textEntryBox entryContents);
	  break;
	case WINDELETE:
 	  mainWindow deleteAndClose;
	  exit (0);
	  break;
	}
    } else {
      usleep (1000);
    }
  }

}

Resources

X11TextEntryBox objects do not define resources of their own. Instead, it uses the resources defined by the classes of its components:

X11YesNoBoxPane See X11YesNoBoxPane.
X11LabelPane See X11LabelPane.
X11ButtonPane See X11ButtonPane.
X11TextEntryPane See X11TextEntryPane.

The top-level window’s resources are defined by the X11YesNoBox superclass. Each of the component subpanes is defined by an instance variable. This allows each of the subpanes to be managed individually.

lbutton

Defined by the X11ButtonPane class. See X11ButtonPane.

rbutton

Defined by the X11ButtonPane class. See X11ButtonPane.

label

Defined by the X11LabelPane class. See X11LabelPane.

icon

Defined by the X11Bitmap class. See X11Bitmap.

entryPane

Defined by the X11TextEntryPane class. See X11TextEntryPane.

For example, to change the background color of selected text in the entrybox subwindow, a program would contain a statement like this one.


myEntryBox entryPane resources replaceAt "selectionColor", "lightblue";

Occasionally, the subpane’s class defines its own resources that it propagates to its own subpanes. For example, to change the text that appears on the buttons:


myEntryBox resources replaceAt "leftButtonText", "Dismiss";
myEntryBox resources replaceAt "rightButtonText", "Accept";

It’s necessary to use the Collection : replaceAt method, because each subpane’s default resources has already been created when the subpane is constructed (generally, this is done by each classes’ new method).

Instance Variables

dots

A Boolean that causes the entryPane to echo dots instead of the text that the user typed.

entryContents

A String that contains the text contents of the entry window. This variable is updated whenever the contents of the entryPane object are modified.

entryPane

The X11TextEntryPane object that is constructed when the show method is first called, and is updated and displayed via the show method’s event loop.

Instance Methods

draw (void

Draws the main pane and each subpane’s controls on each subpane’s buffer, as well as the main pane’s icon, if any.

initWidgets (void)

Constructs the subpanes when the entrybox window is first constructed and mapped to the display. The method sets the initialized instance variable (defined in X11YesNoBoxPane class) to true, so the pane is only constructed once if it is withdrawn from the display and then remapped.

new (String paneName)

The X11TextEntryBox constructor. This method calls the constructor of its superclass, X11YesNoBoxPane, which defines the resources that this class uses as well. However, this constructor defines the event handlers it needs, in order to make the events available to the entryPane subpane when necessary.

show (Object subPane, InputEvent event)

This method constructs the X11TextEntryBox object when it is first called, and then on the first and each following call, maps the entry box to the display, waits for and dispatches events from the display server, and withdraws the window from the display when the user clicks on a button or on the window’s close menu.

subPaneEnter (Object subPane, InputEvent event)
subPaneLeave (Object subPane, InputEvent event)

Event handlers for enter and leave events, which are generated when the pointer is over one of the subpanes.


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