Foundation > Rogue Wave Views を X Window システムで使用する > libxviews を使用して Rogue Wave Views を X アプリケーションと統合する > Motif による完全な例
 
Motif による完全な例
Motif は X ベース・ツールキットの例としてのみ選択されています。 Rogue Wave Views と Motif を統合するより良い方法は、これらが既に統合されている標準 Rogue Wave Views ライブラリー libmviews を使用することです。 以下の例は、libmviewsが使用できない場合の処理を示すものです (samples/xlib/ilvmotif.cc):
// -------------------------------------------------------------
// Integration of Views, pure XLib version into a Motif
// application
// -------------------------------------------------------------
#include <ilviews/contain.h>
#include <ilviews/label.h>
 
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <X11/StringDefs.h>
 
// Define the default input mask for the window
#define INPUT_MASK (unsigned long)(ButtonPressMask | \
ButtonReleaseMask | \
KeyPressMask | \
KeyReleaseMask | \
ButtonMotionMask | \
EnterWindowMask | \
LeaveWindowMask | \
PointerMotionMask | \
ExposureMask | \
StructureNotifyMask)
 
// -------------------------------------------------------------
// This will be called by Xt when events of any of the
// types specified in INPUT_MASK occur.
// To do this, we call upon the XtAddEventHandler function call
// (see main()).
// -------------------------------------------------------------
 
static void
ManageInput(Widget, XtPointer view, XEvent* xevent, Boolean*)
{
IlvEventLoop::getEventLoop()->dispatchEvent(xevent);
}
// -------------------------------------------------------------
void
main(int argc,char** argv)
{
// Initialize X Window:
Widget toplevel = XtInitialize("", "IlvXlib", NULL, NULL,
// XtInitialize has a new specific signature in X11r5
#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 5)
&argc,
#else
(Cardinal*)&argc,
#endif
argv);
// If the top shell couldn?t be created, exit
if (!toplevel)
exit(1);
 
// Create a Motif widget to draw to
Widget drawArea = XtVaCreateManagedWidget("ilvview",
xmDrawingAreaWidgetClass,
(Widget)toplevel,
XtNwidth, 400,
XtNheight, 400,
0);
XtRealizeWidget(toplevel);
 
// Create an IlvDisplay instance from the existing Display
IlvDisplay* display = new IlvDisplay(XtDisplay(drawArea), "Views");
 
// Create a container associated with the drawing area:
IlvContainer* container =
new IlvContainer(display, (IlvSystemView)XtWindow(drawArea));
 
// Create a graphic object in the container
container->addObject(new IlvLabel(display,
IlvPoint(30, 30),
"an IlvLabel instance"));
// Let Views know about the events
XtAddEventHandler(drawArea, INPUT_MASK, IlFalse, ManageInput, NULL);
 
// Wait for events to occur
XtMainLoop();
}
ディレクトリー samples/xlib/ には、さまざまなツールキットに適用される例が他にも含まれています。 ilvmotif.cpp は Motif との統合の別の例です。同様に、ilvolit.cpp は OpenWindow との統合、ilvxview.cpp は、Xview との統合を示しています。

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.