cowan@dover.sps.mot.com (Andrew H Cowan) (10/23/90)
Can anyone out there tell me what I'm doing wrong in the following code? I'm trying to create a window within (beneath ?) an Athena Viewport widget that I can use to draw text & graphics. When I try to create an Xlib "SimpleWindow" with the previously create Athena Viewport widget as the parent I get this error: X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 1 (X_CreateWindow) Resource id in failed request: 0x0 Serial number of failed request: 5 Current serial number in output stream: 17 What am I doing wrong? -AC ** / \ ** ** ** | | ** ** ** ** \___/ ** ** ******** ** ** ****** __ ** **** ** \_/oo\_/ **** ** ........**..........\||/................****.........**........... Andy Cowan...........||.............cowan@soleil.sps.mot.com......
cowan@dover.sps.mot.com (Andrew H Cowan) (10/23/90)
(Oooops forgot to include the code I need help with....)
Can anyone out there tell me what I'm doing wrong in the following
code? I'm trying to create a window within (beneath ?) an Athena
Viewport widget that I can use to draw text & graphics.
When I try to create an Xlib "SimpleWindow" with the previously
create Athena Viewport widget as the parent I get this error:
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 1 (X_CreateWindow)
Resource id in failed request: 0x0
Serial number of failed request: 5
Current serial number in output stream: 17
What am I doing wrong?
-AC
** / \ **
** ** | | **
** ** ** \___/ ** **
******** ** **
****** __ ** ****
** \_/oo\_/ **** **
........**..........\||/................****.........**...........
Andy Cowan...........||.............cowan@soleil.sps.mot.com......
========================CUT HERE=================================
/* compile: cc -g -o this thisfile.c -lXaw -lXmu -lXext -lXt -lX11 */
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Text.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Viewport.h>
Widget Toplevel; /* The Top of the widget hierarchy */
main(argc, argv)
int argc;
char *argv[];
{
XtAppContext xdvappcon;
Widget viewport,vpform,box;
Window win;
Arg viewportargs[10];
int j;
Toplevel = XtAppInitialize( &xdvappcon, "xaw",
NULL, 0,
&argc, argv,
NULL,
NULL, 0 );
j=0;
XtSetArg( viewportargs[j], XtNforceBars, TRUE); j++;
XtSetArg( viewportargs[j], XtNwidth, 100); j++;
XtSetArg( viewportargs[j], XtNheight, 100); j++;
viewport = XtCreateManagedWidget( /* Viewport with scroll bars */
"viewport",
boxWidgetClass,
Toplevel,
viewportargs, j);
win = XCreateSimpleWindow( /* A window parented by Viewport */
XtDisplay( viewport ),
XtWindow( viewport ),
10, 10, 50, 50, 1, 1, 1 );
XMapWindow( XtDisplay( viewport ),win );
XtRealizeWidget( Toplevel );
XtAppMainLoop(xdvappcon);
}
etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (10/23/90)
A widget does not have a window until it is realized. You will have to wait until XtRealizeWidget is called before you can use XCreateSimpleWindow. -- Eric Taylor Baylor College of Medicine etaylor@wilkins.bmc.tmc.edu (713) 798-3776
klee@wsl.dec.com (Ken Lee) (10/23/90)
In article <2436@dover.sps.mot.com>, cowan@dover.sps.mot.com (Andrew H Cowan) writes: |> When I try to create an Xlib "SimpleWindow" with the previously |> create Athena Viewport widget as the parent I get this error: |> |> X Error of failed request: BadWindow (invalid Window parameter) |> Major opcode of failed request: 1 (X_CreateWindow) |> Resource id in failed request: 0x0 If this isn't in the "frequently asked questions" list, it should be. You are trying to access the XtWindow() of a widget that has not yet been realized. You must realize the window before using XtWindow(). A bigger problem you have is that mixing Xlib and X Toolkit windows this way is a messy kludge. You're much, much better off writing your own widget to handle your Xlib graphics. That way, all of the X Toolkit event, resource, and geometry management facilities will be available to help you, rather than get in your way. Writing a widget is no more complex than mixing Xlib with Xt. Asente & Swick's book "X Window System Tookit" contains an excelent tutorial on writing widgets. -- Ken Lee DEC Western Software Laboratory, Palo Alto, Calif. Internet: klee@wsl.dec.com uucp: uunet!decwrl!klee
neilb@dcs.leeds.ac.UK (Neil Bowers) (10/23/90)
You said: > When I try to create an Xlib "SimpleWindow" with the previously > created Athena Viewport widget as the parent I get this error: X Error of failed request: BadWindow (invalid Window parameter) Your code: .. viewport = XtCreateManagedWidget( "viewport", boxWidgetClass, <-- viewportWidgetClass ?? ... ); <-------+ win = XCreateSimpleWindow( .. ); | XMapWindow(XtDisplay(viewport),win); | XtRealizeWidget(Toplevel); --------+ .. A widget's window is created when the widget is realized, rather than when the widget is created. Realizing after you create the viewport will get the thing to compile and run, but there is still a serious flaw. The viewport widget will manage a single child *widget*, but not a window. I would suggest you create your own widget which encapsulates the functionality required for the window (see chapter 7 of the Xaw doc on creating new widgets). Hope this helps! Neil =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= = Neil Bowers, JANET : neilb@leeds.dcs = = School of Computer Studies, UUCP : ukc!leeds.dcs!neilb = = University of Leeds, EARN/BITNET : neilb@dcs.leeds.ac.uk = = Leeds LS2 9JT. PHONE : +44 532 335478 = =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= = ignoring the bad things makes you end up believing that bad = = things never happen Julian Barnes = =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
moss@brl.mil (Gary S. Moss (VLD/VMB) <moss>) (10/23/90)
In article <1990Oct22.151528@wsl.dec.com>, klee@wsl.dec.com (Ken Lee) writes: |> A bigger problem you have is that mixing Xlib and X Toolkit windows |> this way is a messy kludge. You're much, much better off writing your |> own widget to handle your Xlib graphics. That way, all of the X |> Toolkit event, resource, and geometry management facilities will be |> available to help you, rather than get in your way. Writing a widget |> is no more complex than mixing Xlib with Xt. Asente & Swick's book "X |> Window System Tookit" contains an excelent tutorial on writing |> widgets. I'm sure Ken is right, but you don't really need to write a special purpose widget to do Xlib graphics. I use a core widget "widgetClass" and it works just fine. Initially, I made it a child of a viewport widget, but found that dealing with scroll bars to be less desirable than dragging the image around with the mouse. Now I just use a core widget as a direct child of a form widget and use Xlib calls to draw in a Pixmap and XCopyArea to keep my poor man's graphics widget up to date. No problems so far... Good luck, -Gary