🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: ba.windows.x
Article #91

Help to new X programmer, code included

#91
From: Brett 'Volleyball Is My Game' Ke...
Date: Tue, 28 Jan 1992 21:11
252 lines
8921 bytes
Hi there,

Thanks in advance for any help.  BTW, this code is run on a SPARCstation II
under twm with X V11 R4.

I'm new to X, at this time I'm learning by reading the O'Reilly books and
trying stuff out.  I have some fundamental questions and I have included
my test program.  I'll put comments in by the code sections where necessary.

I don't seem to have any luck finding the data structures and types
that are listed in the argument lists for the different Xt calls.  The widgets
list the include files that are needed for the widgets, but the Xt calls do
not list the include files for the types of their arguments.  Any pointers
here will be appreciated.  Note here that I have tried "grep"ping the include
files in /usr/include/X11 tree.  Perhaps I am not sophisticated enough with
my grep; nevertheless, I don't think this is the way to go.  It would be
much better to have listed the include files needed with the calls.

I'd like to know where to find the resources that I can set on things
such as application shells, popup shells, etc.  Again, for the widgets these
resources are listed in the documentation of the widget, but not for the Xt
calls.  So if I'd like to use XtSetArg to set the background color for a
popup shell, what is the resource name and where do I find the valid values
to which that resource can be set?  See comment with label Note 1.

With each invocation of the program, that is each time I execute the program,
the initial window comes up the size I want it, but not in the place I've
told it to come up (50, 50).  It starts in one location and on the next
invocation it comes up 30 pixels to the right and down of the previous start
location.  Why?  See Note 2.

With my popup widget, no matter where I tell it to come up, it comes up +1
in the x and +53 in the y more than where I told it.  See Note 3.

How can I turn off the window manager menus that appear as a result of button
pushes on the title bar just for this application?

I've seen the type of popup that shows a frame of the popup when called up
and allows the user to place it with the mouse and actually pop it up with
a second mouse click in the position of the mouse cursor.  How do you do
this?

See Note 4.  When I want to orient the buttons either into columns or rows
I'm to set the XtNorientation arg, but no matter which I name it comes up
with the buttons on the same row.  Why?

#include <stdio.h>

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/cursorfont.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Cardinals.h>
#include <X11/Xaw/Label.h>

/*
	The "fallback_resources" are characteristics of the application
	that are essentially defaults.  The user can alter two files,
	/usr/lib/X11/app-defaults/button or $HOME/.Xdefaults, to specify
	some of these resources, but just in case we can say what they
	will be if the user does not change them.
*/

String fallback_resources[] =
	{
	"*title:		Button Demo",
	"*Background:		black",
	"*Foreground:		white",
	NULL
	};

/*
	Other global variables for this program
*/

#define	MAXARGS			10

Arg		args[MAXARGS];
int		num_args = 0;
XtAppContext	app_con;
Widget		topLevel, topForm, demoTitle, buttonBox, button;
Widget		popupShell, popupLabel;


/*****************************************************************************\
 *									     *
 *  This function is called when the first button is pressed.                *
 *									     *
\*****************************************************************************/
void button1Push( widget, client_data, call_data )

Widget widget;
XtPointer client_data, call_data;

  {
  if ( XtIsManaged( popupShell ))
    {
    XtPopdown( popupShell );
    XtUnmanageChild( popupShell );
    }
  else
    {
    XtManageChild( popupShell );
    XtPopup( popupShell, XtGrabNone );
    }
  }

/*****************************************************************************\
 *									     *
 *  This function is called when the quit button is pressed.                 *
 *									     *
\*****************************************************************************/
void killMe( widget, client_data, call_data )

Widget widget;
XtPointer client_data, call_data;

  {
  exit( 1 );
  }


main( argc, argv )

int argc;
char **argv;

  {
  Cursor target, spraycan;

/*
  Initialize the Toolkit, set the fallback resources, and get the application
  context associated with this application.
*/

/*
Note 2: It does not come up in this location.
*/
  XtSetArg( args[num_args], XtNx, 50 );	num_args++;
  XtSetArg( args[num_args], XtNy, 50 );	num_args++;
  XtSetArg( args[num_args], XtNheight, 300 );	num_args++;
  XtSetArg( args[num_args], XtNwidth, 500 );	num_args++;
  topLevel = XtAppInitialize	(
		&app_con, "brettDemo", NULL, ZERO, &argc,
		argv, fallback_resources, args, num_args );
/*
End Note 2
*/

/*
	Create the cursors that I want to use in this program.
*/

  target = XCreateFontCursor( XtDisplay( topLevel ), XC_target );
  spraycan = XCreateFontCursor( XtDisplay( topLevel ), XC_spraycan );


  topForm = XtCreateManagedWidget	(
		"topform", formWidgetClass, topLevel, args, num_args );

  num_args = 0;
  XtSetArg( args[num_args], XtNlabel, "Brett's Button Demo" );	num_args++;
  demoTitle = XtCreateManagedWidget	(
		"title", labelWidgetClass, topForm, args, num_args );

  num_args = 0;
  XtSetArg( args[num_args], XtNfromVert, demoTitle );	num_args++;
/*
Note 4: No matter which I choose, vertical or horizontal, they always come
	up on a single row - the horizontal choice I believe.
*/
  XtSetArg( args[num_args], XtNorientation, XtEvertical );	num_args++;
/*
  XtSetArg( args[num_args], XtNorientation, XtEhorizontal );	num_args++;
*/
/*
End Note 4
*/
  buttonBox = XtCreateManagedWidget	(
		"buttonbox", boxWidgetClass, topForm, args, num_args );

  num_args = 0;
  XtSetArg( args[num_args], XtNlabel, "Button_1" );	num_args++;
  XtSetArg( args[num_args], XtNcursor, target );	num_args++;
  button = XtCreateManagedWidget	(
		"button_1", commandWidgetClass, buttonBox, args, num_args );
  XtAddCallback( button, XtNcallback, button1Push, NULL );

  num_args = 0;
  XtSetArg( args[num_args], XtNlabel, "Quit" );		num_args++;
  XtSetArg( args[num_args], XtNcursor, spraycan );	num_args++;
  button = XtCreateManagedWidget	(
		"quit", commandWidgetClass, buttonBox, args, num_args );
  XtAddCallback( button, XtNcallback, killMe, NULL );

  num_args = 0;
/*
Note 1:  I'd like to do an XtSetArg here to set the background to white
	 and the foreground to black.
*/

/*
Note 3: This does come up in same location each time, but +1 in the x direction
	and +53 in the y direction, that is at 301, 253
*/
  XtSetArg( args[num_args], XtNx, 300 );	num_args++;
  XtSetArg( args[num_args], XtNy, 200 );	num_args++;
/*
End Note 3
*/
  XtSetArg( args[num_args], XtNheight, 200 );	num_args++;
  XtSetArg( args[num_args], XtNwidth, 300 );	num_args++;
  XtSetArg( args[num_args], XtNtitle, "Brett's Popup" );	num_args++;
  popupShell = XtCreatePopupShell	(
		"popup", transientShellWidgetClass, topLevel, args, num_args );
/*
End Note 1
*/

  num_args = 0;
  XtSetArg( args[num_args], XtNlabel, "Button 1 Label" );	num_args++;
  popupLabel = XtCreateManagedWidget	(
		"label", labelWidgetClass, popupShell, args, num_args );

/*
  This will bring up the main window for the application 
*/

  XtRealizeWidget( topLevel );

/*
  Now process the events.
*/

  XtAppMainLoop( app_con );
  }

-------------------------------------------------------------------------------
Brett M. Kettering
PaperNet: LLNL P.O. Box 808 L-437 Livermore, CA.  94551
InterNet: KETTERING1@llnl.gov
TalkNet : (510) 423-3467
Fax     : (510) 423-4606

Unknown Debater: "We need a national speed limit of 55 mph."
Homer Simpson  : "Oh sure, it might save a few lives, but millions
		  would be late."
Sammy Hagar    : "I can't drive 55."
-------------------------------------------------------------------------------
Technical Details
Message-ID: <28JAN199214114066@addvax.llnl.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!lll-winken!addvax.llnl.gov!kettering

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10e286,1d460893d7b8339d,start
X-Google-Attributes: gid10e286,public
X-Google-ArrivalTime: 1992-01-28 14:18:04 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!lll-winken!addvax.llnl.gov!kettering
From: kettering@addvax.llnl.gov (Brett 'Volleyball Is My Game' Kettering)
Newsgroups: ba.windows.x
Subject: Help to new X programmer, code included
Message-ID: <28JAN199214114066@addvax.llnl.gov>
Date: 28 Jan 92 21:11:00 GMT
Sender: usenet@lll-winken.LLNL.GOV
Distribution: usa
Organization: Lawrence Livermore National Laboratory
Lines: 252
Nntp-Posting-Host: addvax.llnl.gov
News-Software: VAX/VMS VNEWS 1.40