Foundation > Using Rogue Wave Views on X Window Systems > Integrating Rogue Wave Views with a Motif Application using libmviews > Sample Program Using Motif and Rogue Wave Views
 
Sample Program Using Motif and Rogue Wave Views
The following sample program is a full example of how to integrate Rogue Wave Views code into a Motif application (samples/foundation/xlib/src/ilvmotif.cpp):
// -------------------------------------------------------------- -*- C++ -*-
// Rogue Wave Views samples source file
// File: samples/foundation/xlib/src/ilvmotif.cpp
// --------------------------------------------------------------------------
// Using the grapher in a Motif widget
// --------------------------------------------------------------------------
#include <ilviews/contain/contain.h>
#include <ilviews/graphics/all.h>
#include <stdio.h>
#include <stdlib.h>
 
// --------------------------------------------------------------------------
// Integration Part with Motif
// --------------------------------------------------------------------------
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xlib.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/PushB.h>
 
// --------------------------------------------------------------------------
static void
Quit(Widget, XtPointer display, XtPointer)
{
delete (IlvDisplay*)display;
exit(0);
}
 
#define INPUT_MASK (unsigned long)(ButtonPressMask | ButtonReleaseMask |\
KeyPressMask | KeyReleaseMask |\
ButtonMotionMask | EnterWindowMask |\
LeaveWindowMask | PointerMotionMask | \
ExposureMask | StructureNotifyMask)
 
extern "C" void IlvDispatchEvent(XEvent* xevent);
 
static void
ManageInput(Widget, XtPointer, XEvent* xevent, Boolean*)
{
IlvDispatchEvent(xevent);
}
 
// --------------------------------------------------------------------------
IlvDisplay*
IlvGetDisplay(Display* xdisplay)
{
static IlvDisplay* ilv_display = 0;
if (!ilv_display)
       ilv_display = new IlvDisplay(xdisplay, "IlvMotif");
return ilv_display;
}
 
// --------------------------------------------------------------------------
IlvContainer*
CreateContainer(Widget widget)
{
IlvContainer* c = new IlvContainer(IlvGetDisplay(XtDisplay(widget)),
(IlvSystemView)XtWindow(widget));
XtAddEventHandler(widget, INPUT_MASK, False,
ManageInput, (XtPointer)c);
return c;
}
 
// --------------------------------------------------------------------------
int
main(int argc, char* argv[])
{
Widget toplevel = XtInitialize("", "IlvMotif", NULL, 0,
&argc, argv);
if (!toplevel)
exit(1);
Widget drawArea = XtVaCreateManagedWidget("ilvview",
xmDrawingAreaWidgetClass,
(Widget)toplevel,
XtNwidth, 400,
XtNheight, 400,
(IlAny) 0);
Widget pushb = XtVaCreateManagedWidget("Quit",
xmPushButtonWidgetClass,
drawArea,
(IlAny) 0);
XtRealizeWidget(toplevel);
IlvContainer* container = CreateContainer(drawArea);
XtAddCallback(pushb, XmNactivateCallback, Quit, container->getDisplay());
container->readFile("demo2d.ilv");
XtMainLoop();
return 0;
}

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.