[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Message(3X) manual page Table of Contents

Name

Message - display uneditable text or bitmap label

Synopsis

#include <ivplus/message.h>

Description

Message is an interactor which displays a label. The label is either non-editable text or a bitmap.The text may include newlines (specified by ’\n’). The alignment of the label with respect to the interactor’s canvas can be specified in the constructor, as can the amount of padding around the message and the amount of horizontal and vertical stretch. In addition, an internal resize policy may be specified which will cause the message to either change its shape to accommodate modifications to the label or to remain at a fixed size. These may be specified by the resize policies ShrinkToFit and FixedSize, respectively. If FixedSize is specified, then the values of fixedWidth and fixedHeight determine what size the message will be.

Internal margins may be specified for top, left, bottom, and right. These margins require that the label be no closer to the indicated edge than the appropriate margin value when alignment is performed. These margins are used mainly for aligning fields within menuitems.

Derived classes which modify left-to-right appearance only should override XAlign(). The overridden XAlign() should call Message::XAlign() and then modify the returned value accordingly to alter the location at which the label will be drawn.

Class Hierarchy

Message->Interactor

Constructors

Message(const char* msg, Alignment al = Center, int pad = 0, int hstretch = 0, int vstretch = 0, LabelResizePolicy = NoPolicy, int fixedWidth = 0, int fixedHeight = 0)

Message(const char* name, const char* msg, Alignment al = Center, int pad = 0, int hstretch = 0, int vstretch = 0, LabelResizePolicy = NoPolicy, int fixedWidth = 0, int fixedHeight = 0)

Create a new message with the indicated text and alignment. Alignments are interpreted as follows:

Center
Center-justify each line of text.
Left
Left-justify each line of text.
Right
Right-justify each line of text.

Text will be surrounded by pad pixels of whitespace. Stretchability of the message is set to be hstretch and vstretch. Resize policy defaults to ShrinkToFit unless otherwise indicated. Use the indicated fixedWidth and fixedHeight if FixedSize is the resize policy.

Message(Bitmap* image, Alignment al = Center, int pad = 0,int hstretch = 0, int vstretch = 0, LabelResizePolicy = NoPolicy, int fixedWidth = 0, int fixedHeight = 0)

Message(const char* name, Bitmap* image, Alignment al = Center, int pad = 0, int hstretch = 0, int vstretch = 0, LabelResizePolicy = NoPolicy, int fixedWidth = 0, int fixedHeight = 0)

Create a new message with the indicated bitmap and alignment. Alignments are interpreted as follows:

Center
Center-justify the bitmap.
Left
Left-justify the bitmap.
Right
Right-justify the bitmap.

The bitmap will be surrounded by pad pixels of whitespace. Stretchability of the message is set to be hstretch and vstretch. The resize policy defaults to ShrinkToFit unless otherwise indicated. Use the indicated fixedWidth and fixedHeight if FixedSize is the resize policy.

Message(Message* msg)

Creates a new message with the same settings as msg. Text is duplicated and reference count of bitmap is incremented if the bitmap is not nil.

Public Data

enum { TextDisplayType, ImageDisplayType } DisplayType

This type is used to determine if message should display text or a bitmap as its label. Its declaration is found in interactor.h.

enum { FixedSize, ShrinkToFit, NoPolicy } ResizePolicy

Used to determine how the shape should be calculated. ShrinkToFit will make the shape just large enough to fit the image or text on the display.

Public Operations

Alignment Align()

Returns the current alignment.

void Align Alignment()

Sets the current alignment.

virtual unsigned BottomMargin()

Returns the current value used for bottom margin.

virtual void BottomMargin(unsigned)

Sets the bottom margin to the indicated value.

unsigned FixedWidth()

Returns the current width used when ResizePolicy() is FixedSize.

unsigned FixedHeight()

Returns the current height used when ResizePolicy() is FixedSize.

void FixSizes(unsigned width, unsigned height)

Sets the width and height to use when ResizePolicy() is FixedSize.

char* GetLine (int)

Returns the string associated with the given line number.

virtual void Highlight(boolean)

This will set the highlight of the display to true or false. When a message is highlighted, the foreground and background colors are exchanged.

Bitmap* Image()

Returns a pointer to the current bitmap image.

virtual int LabelHeight()

Returns the amount of space required by the current label. If LabelType() is ImageDisplayType, this operation will return the bitmap’s height, otherwise it will return the height of the current text including spacing between lines.

DisplayType LabelType()

Returns the current type of label in use, either ImageDisplayType or TextDisplayType.

void LabelType(DisplayType)

Sets the current type of label to use, either ImageDisplayType or TextDisplayType.

virtual int LabelWidth()

Returns the width of the current label. If LabelType() is ImageDisplayType, returns the width of the current bitmap, otherwise returns the width of the longest line of text in the current font.

int Led()

Returns the amount of space included between any two lines of text.

virtual unsigned LeftMargin()

Returns the current value used for left margin.

virtual void LeftMargin(unsigned)

Sets the left margin to the indicated value.

int LineCount()

Returns the number of lines in the message.

const Painter* Output()

Returns a pointer to the output painter.

unsigned Pad ()

Returns the amount of padding surrounding the label.

void Pad(unsigned)

Sets the amount of padding to surround the label.

virtual void Realign(Alignment)

This dynamically changes the alignment of the message to the indicated alignment. Valid alignment types are: Left, Center and Right.

LabelResizePolicy ResizePolicy()

Returns the current resize policy.

void ResizePolicy(LabelResizePolicy p)

Sets the current resize policy to the indicated value. Valid policies are ShrinkToFit (large enough to fit the current label and padding) and FixedSize (use the current values of fixedWidth and fixedHeight to determine size). If the resize policy changes from ShrinkToFit to FixedSize and the fixed width and height have not been set, the current size will become the fixed size.

virtual unsigned RightMargin()

Returns the current value used for bottom margin.

virtual void RightMargin(unsigned)

Sets the left margin to the indicated value.

char** Text()

Returns the array of text lines currently being used. It contains LineCount() elements. They must not be modified.

virtual unsigned TopMargin()

Returns the current value used for bottom margin.

virtual void TopMargin(unsigned)

Sets the left margin to the indicated value.

virtual boolean Traversable()"

Returns whether or not the message participates in keyboard traversal.

virtual void UpdateImage(Bitmap* image)

Makes image the current label. If the canvas is not nil, the shape is recomputed according to the current resize policy and the parent scene is notified of any change.

virtual void UpdateImage(const char* imageFile)

Makes the results of Bitmap::open(imageFile) the current label. If the canvas is not nil, the shape is recomputed according to the current resize policy and the parent scene is notified of any change.

virtual void UpdateText(const char**)

Replaces the current text in the message with the passed character array. If the canvas is not nil, the shape is recomputed according to the current resize policy and the parent scene is notified of any change.

virtual void UpdateText(const char*)

Replaces the current text in the message with the passed string. The string is checked for new line characters (’\n’) and broken into multiple lines where they are encountered. If the canvas is not nil, the shape is recomputed according to the current resize policy and the parent scene is notified of any change.

virtual void UpdateText(const char*, int index)

Replace the text at line index with the passed string. If the canvas is not nil, the shape is recomputed according to the current resize policy and the parent scene is notified of any change. The passed text should not contain any newline characters. If they are found, the substitution will not be performed.

Protected Data

virtual void DrawImage()

Draws the current bitmap on the canvas according to the margin values and current alignment.

virtual void DrawText()

Draws the lines of text in the message, evaluating each line and modifying the left coordinate depending on the alignment used.

Protected Operations

virtual void Reconfig()

Checks to see if attribute have been set in the X resource file. (See the X RESOURCES section below for a complete list of attributes.) If any have been set, evaluates those values and places the results in the corresponding internal variables. Calculates the size of the message using widest line of text and line height of all the lines, or the width of the bitmap.

virtual void Redraw(IntCoord left, IntCoord bottom, IntCoord right, IntCoord top)

Sets the clip region, clears the canvas, sets the foreground and background colors as appropriate for the current value of highlighted and invokes DrawText(). If LabelType() is ImageDisplayType invokes DrawImage() instead of DrawText(). Resets the colors if necessary and remove the clip region.

virtual void XAlign(const char*, int& x)

Computes the initial x position of the indicated piece of text using the current alignment, margins, and canvas size. Derived classes which modify left-to-right appearance only should override XAlign(). The overridden XAlign() should call Message::XAlign() and then modify the returned value accordingly to alter the location at which the label will be drawn.

virtual void XAlign(Bitmap*, int& x)

Computes the initial x position of the indicated bitmap using the current alignment, margins, and canvas size. Derived classes which modify left-to-right appearance only should override XAlign(). The overridden XAlign() should call Message::XAlign() and then modify the returned value accordingly to alter the location at which the label will be drawn.

X Resources

bottomMargin:[n]

Sets the amount of white space which must be maintained between the bottom of the label and the bottom of the canvas.

fixedHeight:[n]

Sets the height required by message when resizePolicy is FixedSize.

fixedWidth:[n]

Sets the width required by message when resizePolicy is FixedSize.

image:[string]

Sets the filename of the bitmap to use when LabelType() is ImageDisplayType.

leftMargin:[n]

Sets the amount of white space which must be maintained between the left end of the label and the left edge of the canvas.

rightMargin:[n]

Sets the amount of white space which must be maintained between the right end of the label and the right edge of the canvas.

padding:[n]

Sets the amount of white space padding (in pixels) that surrounds the message to n.

resizePolicy:[ShrinkToFit/FixedSize]

Sets the internal resize policy. ShrinkToFit instructs message to request only as much room as needed for label and padding. FixedSize instructs message to require fixedWidth space for width and fixedHeight space for height.

text:[string]

Sets the text of the message to string. This string may contain newline (\n) characters.

topMargin:[n]

Sets the amount of white space which must be maintained between the top of the label and the top of the canvas.

Default Keyboard Translations

None.

Examples


//                          Message Example
#include <ivplus/box.h>
#include <ivplus/frame.h>
#include <ivplus/glue.h>
#include <ivplus/message.h>
#include <ivplus/world.h>
        
int main(int argc, char **argv)
{
   // Create the world to get the connection with the display.
   World* world = new World("MyApp", argc, argv);
  
   // Create a message with default alignment, padding, vstretch and hstretch.
   Message* msg1 = new Message("Hello World");
   // Create a message with 5 pixel padding, Center Alignment,
   // 0 vstretch and 0 hstretch.
   Message* msg2 = new Message("Hello World", Center, 5, 0, 0);
   // Create a message with center alignment, 5 pixel padding,
   // infinite vstretch and hstretch.
   Message* msg3 = new Message("Hello World", Center, 5, hfil, vfil);
   // Create a multi-line message with default pixel padding, vstretch
   // and hstretch. 
   Message* msg4 = new Message("This is Line 1\nThis is Line 2");
  
   // Enclose each message in a Frame and insert it in a VBox.
   VBox* box = new VBox(new Frame(msg1), new Frame(msg2),
                         new Frame(msg3), new Frame(msg4));
   // Map the window.
   world->InsertApplication(new Frame(box, 1, BevelOut));
   // Enter the event loop.
   world->Run();
   return 0;
}

Files


message.h
message.C

See Also

Bitmap(3X) , Canvas(3X) , Interactor(3X) , Painter(3X) .


Table of Contents