XVisual support library. Updated for 1.0.5 BETA

Contents:

Return to XVisual Homepage

What libxv does

The xv support library 'libxv' is a C++ class library which allows Athena widgets to be handled much easier than if they were being programmed directly. A Widget instance is created simply by declaring an object of a particular type. Each widget instance is then controlled by a set of 'methods' for that particular object class. A set of 'core' object methods provide basic control of the widgets, with object methods providing control over widget-specific resources. These methods are the preferred way of setting widget resources, although the programmer may use Xt and/or Xlib calls without causing any problems to xv since the library will update it's own information anyway.

Libxv comes in two versions, static and shared. Note that if you opt to use the shared version, you will require that the target system has the shared libxv libraries installed.

NOTE: A knowledge of the Athena Widget Library is recommended since it's beyond the scope of this document to list every resource of each Widget.

An Example program construction using libxv

It's probably easier to show you a simple libxv program and to describe its construction...

#include X11/xv/xv.h

Boolean application_exit=FALSE;

void cmd_exit(Widget aw, XtPointer client, XtPointer call)
{
	application_exit=TRUE;
}

main(int argc, char **argv)
{
	xvContext app_context;
	xvWindow app_window;
	xvButton app_exit;

//	Now Initialise the Objects...

	app_context.init("example", argc, argv);

	app_window.init("Example libxv program", "example", app_context);

	app_exit.init("Exit", app_window, cmd_exit);
	app_exit.SetDistance(50, 50);
	app_exit.SetFixedPosition(TRUE);

	app_window.SetWindowResource(XtNgeometry, (XtArgVal) "400x400");
	app_window.Open();

	while (! application_exit)
		app_context.ServiceEvent();

	app_window.Close();

}

This simple program displays a window with a button near to top-left corner. Pressing the button causes the window to close and the program to exit.

The construction is pretty simple, but shows the basic concepts needed to use libxv successfully.

The first line includes the X11/xv/xv.h header file which is required for all programs using libxv.

A global Boolean variable "application_exit" is declared. This will signal the program to exit, and is set in the callback function cmd_exit. A callback is a function which is called by a widget when a certain event occurs - in this case when the button is pressed. Callbacks have the same structure, must be declared void (this type of function is typedef'ed by Xt) and have the same three parameters (Widget and two XtPointers). An XtPointer is a pointer to data which may be passed from the widget calling the function and may be cast as required. For example, if you had a group of buttons using the same callback, each could pass a unique item of data to the function to identify which button was pressed.

Many objects have callbacks to perform different actions, and they may also have event callbacks to perform actions in certain circumstances. Event callbacks have a different parameter list and are covered later. The xvTimer object has a timeout callback which is called at a specific interval, and again has different parameters.

On to the main section, and we declare three objects; an xvContext, an xvWindow and an xvButton. Every program using libxv must have an xvContext which declares the programs 'application context'; a data structure used by Xt to manage a program currently running. Most programs will require an xvWindow object in order to display anything at all. A program may have several xvWindows (and may also have multiple xvContexts, although it's unlikely) to display different information.

In this example, we use one window and one xvButton object.

Each xv object has an init function and the order of initialisation is important. An xvContext object is the 'parent' of anything that is declared within it's scope, these objects being it's 'children'. The xvWindow object is the 'child' of xvContext, but anything that appears within that window is the window's child. Most libxv objects require the name of the parent to be passed to them during initialisation, the exception being the xvContext itself.

In this example, the first init function called is the xvContext.init function, which takes a string name, argc and argv as parameters. Next, the xvWindow object is declared. This takes a string (the window title), a string (the classname) and a context name (in this case the app_context object declared as xvContext).

Now we can initialise the button which takes a string (the button name and it's label), a parent name (in this case the xvWindow object) and a pointer to callback function to be executed when the button is pressed. Note that xvButton objects can take an optional 4th paramter, which is a string containing 'client' data to be passed to the callback.

Additionally, the core SetDistance method is used to position the button at co-ordinates 50, 50 on the window (0,0 = top left of window) and the core SetFixedPosition method is called to fix it's position and size (otherwise Xt would change its size if the window was resized - to see what happens, comment this line out!)

Before opening the window with the xvWindow Open method, we make a call to the xvWindow SetWindowResource method to set the size of the window to 400x400 pixels. Note that this is done just before opening the window because objects declared before sometimes cause Xt to automatically resize the window, which may not be what you want. In the Xvisual Interface Builder, you can set and fix the window size if you wish.

The xvWindow Open method is called to actually open and display the window and it's child objects. It is at this point that Xt realizes all the widgets and displays them in the requested positions.

The while loop repeatedly calls the xvContext's ServiceEvent method which retrieves and processes X Window events. This will continue until the value of 'application_exit' becomes TRUE whereupon the loop exits and the xvWindow Close method is called and the program exits.

NOTE: Although we used the init methods to initialise the instances of these objects, we could just have easily written:


main(int argc, char **argv)
{
	...
	xvWindow *app_window=new xvWindow("Example libxv program", 
		"example", app_context);
	...
	etc..
}

Note that because we would be using a pointer to a class, methods would be called using the -> operator (e.g. app_window->Open();) and references to the object would require '*' (e.g. *app_window).

Compiling a libxv program

The above program can be compiled as follows:

g++ -c -o example.o example.cc

g++ -L/usr/X11/lib -o example example.o -lxv -lXaw3D -lXmu -lXt -lSM -lICE -lXext -lX11

The need for a Makefile is obvious and an example Makefile is shown later. The XIB generates it's own makefiles depending on the forms and modules currently loaded, but the basic structure is pretty much the same.


Core methods common to most objects

Core methods as those defined in the xvCore class which is inherited by the majority of objects in libxv. These allow you to change the basic resources of a particular object without having to use Xt argument lists or the XtVaSet/Getvalues calls. Although these methods are the preferred way to change object resources, you can still use the Xt routines since libxv will update it's own information as required.

All methods return 'void' unless otherwise indicated

Where the parameter 'xvObject & parent' appears, simply pass the name of the instance of the class of the parent object.

Core Methods for all xvCore objects

Core Methods for most objects

The methods listed in this sub-section apply only to certain objects such as xvButton and xvLabel which use the particular resource

Constraint Methods

Objects that are children of xvWindow or xvForm objects can use these methods

Three-D methods

Some objects respond to the setting of these resources and thus provide a pseudo-three-D visual effect.

Misc. Methods

These methods were included in the core set for ease of access and use.

Methods for objects handled by the XVisual Interface Builder(XIB)

This section covers the specific methods provided by objects directly handled by the XIB. You can of course create these objects outside the XIB if you wish.

Note that objects with init methods may also be instatiated in the following way:-

Where the parameter 'xvObject & parent' appears, simply pass the name of the instance of the class of the parent object.

XvContext

xvWindow

xvTimer

xvVisualList

xvButton & xvRepeater

xvEditField

xvBitmap

xvLabel

xvPanner

xvBox

xvForm

xvToggle

xvScrollbar

xvFileList & xvDirList

xvDropDown

xvMenuBar

xvPulldownMenu

GC & Graphics methods for xvWindows.

An object of type xvWindow also supports a number of Graphics Context (GC) and Graphics methods. Note that if you are drawing to a window, you will need to arrange for graphics info to be re-drawn should the window be obscured and then exposed. Use the X_Expose event to do this.

Each xvWindow object supports three graphics contexts and you may select the context to be used with the GCSwitchGC(int) method (see below). The GC remains in force until the method is called again.

Graphics Context Methods

Graphics Methods

Other libXV objects

The following objects are also available to the programmer, even though they are not directly supported by the XIB. Just how useful these will be depends pretty much on your application and some of these were intended to be used by the XIB rather than client programs.

xvGrip

xvPopupShell

xvPopupMenu

This class inherits all of xvPopupShell's methods.

xvDialog

xvPopupDialog

This class inherits all of xvPopupShell's methods and all of xvDialog's methods.

xvFileDialog

xvEditWindow

This object inherits methods from xvWindow and xvEditField.

xvMsgBox

xvFont

xvFontList

xvRegion

This object is a libxv representation of the XLib Region calls. Refer to an XLib Programming reference for info on Regions.



Typical Makefile used to compile programs using libxv

Shown below is a typical Makefile generated by the XIB to compile and link programs under libxv. You can copy and modify this to suit your requirements.

CC=g++
CFLAGS= -O
INCLUDES= -I.
XLIBS= -lxv -lXaw3d -lXmu -lXt -lSM -lICE -lXext -lX11
BIN26LINKOPTS=-L/usr/X11/lib

OBJFILES=	example.o window1.o global.o

.cc.o:
	$(CC) -c $(CFLAGS) $(INCLUDES) $*.cc

all:: xvis

xvis:	$(OBJFILES)
		$(CC) $(BIN26LINKOPTS) -o  $@ $(OBJFILES)  $(XLIBS) 

clean:
	rm -f *.o xvis

remake:: clean all

Simply enter the files to be compiled into the 'OBJFILES=' list (with the .o extension instead of .cc) and then type 'make' at the command line.


Return to the XVisual Homepage


Steve Carrie. steve@phoenix.bim.napier.ac.uk

Last Update 24/05/96 at 16:00 hrs