/*
* tkMessage.c --
*
* This module implements a message widgets for the Tk
* toolkit. A message widget displays a multi-line string
* in a window according to a particular aspect ratio.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkMessage.c 1.66 96/02/15 18:52:28
*/
#include "tkInt.h"
#include "tkDefault.h"
/*
* A data structure of the following type is kept for each message
* widget managed by this file:
*/
typedef struct {
* means that the window has been destroyed
* but the data structures haven't yet been
* cleaned up.*/
* other things, so that resources can be
* freed even after tkwin has gone away. */
* including terminating NULL character. */
* If non-NULL, message displays the contents
* of this variable. */
/*
* Information used when displaying widget:
*/
* background. NULL means a border hasn't
* been created yet. */
* around widget when it has the focus.
* <= 0 means don't draw a highlight. */
/* Color for drawing traversal highlight
* area when highlight is off. */
* traversal highlight and 3-D border.
* Indicates how much interior stuff must
* be offset from outside edges to leave
* room for borders. */
* if window is larger or smaller than
* needed. */
* compute width using aspect ratio below. */
* needed to display message. */
/*
* Miscellaneous information:
*/
* the C code, but used by keyboard traversal
* scripts. Malloc'ed, but may be NULL. */
* definitions. */
} Message;
/*
* Flag bits for messages:
*
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler
* has already been queued to redraw
* this window.
* GOT_FOCUS: Non-zero means this button currently
* has the input focus.
*/
/*
* Information used for argv parsing.
*/
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
"HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG,
"HighlightThickness",
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
static void MessageCmdDeletedProc _ANSI_ARGS_((
int flags));
int flags));
/*
*--------------------------------------------------------------
*
* Tk_MessageCmd --
*
* This procedure is invoked to process the "message" Tcl
* command. See the user documentation for details on what
* it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
if (argc < 2) {
return TCL_ERROR;
}
return TCL_ERROR;
}
msgPtr->borderWidth = 0;
msgPtr->highlightWidth = 0;
msgPtr->lineLength = 0;
goto error;
}
return TCL_OK;
return TCL_ERROR;
}
/*
*--------------------------------------------------------------
*
* MessageWidgetCmd --
*
* This procedure is invoked to process the Tcl command
* that corresponds to a widget managed by this module.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
static int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int c;
if (argc < 2) {
" option ?arg arg ...?\"", (char *) NULL);
return TCL_ERROR;
}
c = argv[1][0];
&& (length >= 2)) {
if (argc != 3) {
argv[0], " cget option\"",
(char *) NULL);
return TCL_ERROR;
}
&& (length >= 2)) {
if (argc == 2) {
} else if (argc == 3) {
} else {
}
} else {
"\": must be cget or configure", (char *) NULL);
return TCL_ERROR;
}
}
/*
*----------------------------------------------------------------------
*
* DestroyMessage --
*
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
* to clean up the internal structure of a message at a safe time
* (when no-one is using it anymore).
*
* Results:
* None.
*
* Side effects:
* Everything associated with the message is freed up.
*
*----------------------------------------------------------------------
*/
static void
char *memPtr; /* Info about message widget. */
{
/*
* Free up all the stuff that requires special handling, then
* let Tk_FreeOptions handle all the standard option-related
* stuff.
*/
}
}
}
/*
*----------------------------------------------------------------------
*
* ConfigureMessage --
*
* the Tk option database, in order to configure (or
* reconfigure) a message widget.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side effects:
* Configuration information, such as text string, colors, font,
* etc. get set for msgPtr; old resources get freed, if there
* were any.
*
*----------------------------------------------------------------------
*/
static int
* not already have values for some fields. */
int argc; /* Number of valid entries in argv. */
char **argv; /* Arguments. */
int flags; /* Flags to pass to Tk_ConfigureWidget. */
{
/*
* Eliminate any existing trace on a variable monitored by the message.
*/
}
return TCL_ERROR;
}
/*
* If the message is to display the value of a variable, then set up
* a trace on the variable's value, create the variable if it doesn't
* exist, and fetch its current value.
*/
char *value;
} else {
}
}
}
/*
* A few other options need special processing, such as setting
* the background from a 3-D border or handling special defaults
* that couldn't be specified to Tk_ConfigureWidget.
*/
if (msgPtr->highlightWidth < 0) {
msgPtr->highlightWidth = 0;
}
&gcValues);
}
}
}
/*
* Recompute the desired geometry for the window, and arrange for
* the window to be redisplayed.
*/
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ComputeMessageGeometry --
*
* Compute the desired geometry for a message window,
* taking into account the desired aspect ratio for the
* window.
*
* Results:
* None.
*
* Side effects:
* Tk_GeometryRequest is called to inform the geometry
* manager of the desired geometry for this window.
*
*--------------------------------------------------------------
*/
static void
{
char *p;
/*
* Compute acceptable bounds for the final aspect ratio.
*/
if (aspect < 5) {
aspect = 5;
}
/*
* Do the computation in multiple passes: start off with
* a very wide window, and compute its height. Then change
* the width and try again. Reduce the size of the change
* and iterate until dimensions are found that approximate
* the desired aspect ratio. Or, if the user gave an explicit
* width then just use that.
*/
inc = 0;
} else {
}
for ( ; ; inc /= 2) {
maxWidth = 0;
if (*p == '\n') {
p++;
continue;
}
}
if (*p == 0) {
break;
}
/*
* Skip spaces and tabs at the beginning of a line, unless
* they follow a user-requested newline.
*/
if (*p == '\n') {
p++;
break;
}
p++;
}
}
if (inc <= 2) {
break;
}
if (aspect < lowerBound) {
} else if (aspect > upperBound) {
} else {
break;
}
}
}
/*
*--------------------------------------------------------------
*
* DisplayMessage --
*
* This procedure redraws the contents of a message window.
*
* Results:
* None.
*
* Side effects:
* Information appears on the screen.
*
*--------------------------------------------------------------
*/
static void
{
char *p;
return;
}
/*
* Compute starting y-location for message based on message size
* and anchor option.
*/
break;
break;
default:
break;
}
/*
* Work through the string to display one line at a time.
* Display each line in three steps. First compute the
* line's width, then figure out where to display the
* line to justify it properly, then display the line.
*/
if (*p == '\n') {
p++;
charsLeft--;
continue;
}
&lineLength);
break;
break;
default:
- msgPtr->lineLength;
break;
}
}
p += numChars;
/*
* Skip blanks at the beginning of a line, unless they follow
* a user-requested newline.
*/
charsLeft--;
if (*p == '\n') {
p++;
break;
}
p++;
}
}
}
if (msgPtr->highlightWidth != 0) {
} else {
}
Tk_WindowId(tkwin));
}
}
/*
*--------------------------------------------------------------
*
* MessageEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on messages.
*
* Results:
* None.
*
* Side effects:
* When the window gets deleted, internal structures get
* cleaned up. When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
{
goto redraw;
}
}
if (msgPtr->highlightWidth > 0) {
goto redraw;
}
}
if (msgPtr->highlightWidth > 0) {
goto redraw;
}
}
}
return;
}
}
/*
*----------------------------------------------------------------------
*
* MessageCmdDeletedProc --
*
* This procedure is invoked when a widget command is deleted. If
* the widget isn't already in the process of being destroyed,
* this command destroys it.
*
* Results:
* None.
*
* Side effects:
* The widget is destroyed.
*
*----------------------------------------------------------------------
*/
static void
{
/*
* This procedure could be invoked either because the window was
* destroyed and the command was then deleted (in which case tkwin
* is NULL) or because the command was deleted, and then this procedure
* destroys the widget.
*/
}
}
/*
*--------------------------------------------------------------
*
* MessageTextVarProc --
*
* This procedure is invoked when someone changes the variable
* whose contents are to be displayed in a message.
*
* Results:
* NULL is always returned.
*
* Side effects:
* The text displayed in the message will change to match the
* variable.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static char *
char *name1; /* Name of variable. */
char *name2; /* Second part of variable name. */
int flags; /* Information about what happened. */
{
char *value;
/*
* If the variable is unset, then immediately recreate it unless
* the whole interpreter is going away.
*/
if (flags & TCL_TRACE_UNSETS) {
}
return (char *) NULL;
}
value = "";
}
}
}
return (char *) NULL;
}