|
I'm trying to write a DECwindows/GKS program to circumvent the "full
colormap" problem. It was suggested to me, by the GKS gurus, that
I define a smaller colormap associated with the widget that is passed
to GKS. As I understand it, GKS takes the definitions in the
associated colormap and appends them to the default device colormap.
In the call to XCreateColorMap, I'm getting a stack dump with the
following error message: "not a valid window ID".
If I substitute RootWindow(dpy,0) for XtWindow(toplevel)
in that call, I get a stack dump on the call to DwtFetchWidget with
the same error message.
I'd appreciate any suggestions.
The code follows the formfeed (also posted in DECWINDOWS_PROGRAMMING).
Thanks,
- Terry
#module decw_gks "V1.0"
/*
** AUTHOR:
**
** Terry L. Crean, ISWS/Marlborough
**
**
*/
#include <stdio.h>
#include <gksdefs.h>
#include <descrip.h>
#include <decw$include/DECwDwtApplProg.h>
/* #include <dvr$public.h> */
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#define k_mainwindow 0
#define k_menubar 1
#define k_file_pulldown 2
#define k_file_menu 3
#define GKS$_SUCCESS 0
#define FUNC_SUCCESS 0
#define MIN_X 0.000000
#define MAX_X 0.800000
#define MIN_Y 0.000000
#define MAX_Y 0.609524
#define MIN_PIC_X 0.019048
#define MIN_PIC_Y -.000495
#define MAX_PIC_X 0.780952
#define MAX_PIC_Y 0.590476
#define color1_num 0
#define color2_num 1
#define color3_num 2
#define num_planes 0 /* number of planes in plane mask for XAllocColorCells */
#define num_colors 3 /* number of colors to be set in the color map */
char *UID_database[] = { "decw_gks.uid" };
static int doDefineColor( ), alloc = AllocNone;
static DRMHierarchy Hierarchy;
static DRMType *dummy;
static DwtCallback callback_arg[2];
static char *color1_name="blue", *color2_name="red", *color3_name="green";
static unsigned int status_return; /* return value from XAllocColorCells */
static unsigned long plane_masks_return, pixels_return[num_colors];
Widget toplevel, mainwidget, WidgetID[ 50 ];
Display *dpy;
GC gc;
Screen *screen;
XGCValues xgcv;
Window work_area;
Colormap colormap_id_return;
XColor color_defs[num_colors], scratch;
Bool contig = FALSE;
/*
* Forward declarations
*/
static void error ();
static void exitproc ();
static void WidgetCreated ();
$DESCRIPTOR (item1_text_13, "A Sample Text String");
main( argc, argv)
int argc;
char *argv[];
{
float ratio_x = 0.0, ratio_y = 0.0;
int wsid = 1,
ret_val,
ws_type,
largest_viewport = 2,
stat;
char conid_buffer[256];
struct dsc$descriptor_s conid = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S,
conid_buffer };
DRMCount callback_num = 2;
DRMRegisterArg callback_namevec[] =
{
{ "exitproc", exitproc },
{ "WidgetCreated", WidgetCreated }
};
DwtInitializeDRM();
toplevel = XtInitialize("CASE Engineering Demonstration",
"TopLevel",
NULL,
0,
&argc,
&argv );
dpy = XtDisplay(toplevel);
screen = XDefaultScreenOfDisplay(dpy);
if ( DwtOpenHierarchy( 1,
UID_database,
NULL,
&Hierarchy ) != DRMSuccess )
error( "Can't open hierarchy!" );
/*
** Create a new blank colormap to be associated with the shell widget
*/
colormap_id_return = XCreateColormap (
dpy, /* display */
XtWindow(toplevel), /* window for which the colormap will be created */
XDefaultVisualOfScreen(screen),
alloc ); /* allocation mode */
/*
** Allocate color cells in the newly created colormap
*/
status_return = XAllocColorCells (
dpy,
colormap_id_return,
contig,
&plane_masks_return,
num_planes,
pixels_return,
num_colors );
if (status_return == 0 )
printf ("\n error allocating color cells; return = %d",
status_return);
else /* Store colors in allocated color cells */
{
/*
** Get the values for our colors from the default color map
*/
if (!XAllocNamedColor (dpy,
DefaultColormapOfScreen (screen),
color1_name,
&scratch,
&color_defs[color1_num] ))
printf ("\n Can't get color %d", color1_num);
else
{
color_defs[color1_num].pixel = pixels_return[color1_num];
color_defs[color1_num].flags = DoRed|DoGreen|DoBlue;
}
if (!XAllocNamedColor (dpy,
DefaultColormapOfScreen (screen),
color2_name,
&scratch,
&color_defs[color2_num] ))
printf ("\n Can't get color %d", color2_num);
else
{
color_defs[color2_num].pixel = pixels_return[color2_num];
color_defs[color2_num].flags = DoRed|DoGreen|DoBlue;
}
if (!XAllocNamedColor (dpy,
DefaultColormapOfScreen (screen),
color3_name,
&scratch,
&color_defs[color3_num] ))
printf ("\n Can't get color %d", color3_num);
else
{
color_defs[color3_num].pixel = pixels_return[color3_num];
color_defs[color3_num].flags = DoRed|DoGreen|DoBlue;
}
}
XStoreColors (dpy,
colormap_id_return,
color_defs,
num_colors );
/*
** Set the colormap for the shell widget
*/
XSetWindowColormap (dpy,
XtWindow(toplevel),
colormap_id_return );
DwtRegisterDRMNames( callback_namevec, callback_num );
if ( DwtFetchWidget( Hierarchy,
"mainWindow",
toplevel,
&mainwidget,
&dummy ) != DRMSuccess )
error( "Can't fetch window!" );
/* work_area = XtWindow(mainwidget);
xgcv.background = doDefineColor(2);
xgcv.foreground = doDefineColor(3);
gc = XCreateGC(dpy, work_area, GCForeground | GCBackground, &xgcv);
*/
XtManageChild( mainwidget );
XtRealizeWidget( toplevel );
/*
* Build the connection identifier
*/
sprintf (conid.dsc$a_pointer, "%d", mainwidget );
conid.dsc$w_length = strlen ( conid.dsc$a_pointer );
ret_val = set_up ( &wsid, &largest_viewport, &ratio_x, &ratio_y,
&ws_type, &conid );
if (ret_val == FUNC_SUCCESS)
{
display_pic ( &wsid, &largest_viewport, &ratio_x, &ratio_y,
&ws_type );
}
XtMainLoop ();
end_program ( &wsid );
}
/*
**++
** FUNCTIONAL DESCRIPTION:
**
** This is just an error reporting procedure.
**
**--
*/
void error( char *error_string )
{
printf( "%s\n", error_string );
}
/*
**++
** FUNCTIONAL DESCRIPTION:
**
** This is the exitproc callback routine.
**
** Just exits the program.
**--
*/
void exitproc( w, tag )
Widget *w;
int *tag;
{
exit(1);
}
/*
**++
** FUNCTIONAL DESCRIPTION:
**
** This is the WidgetCreated callback routine.
**
** Registers the widget ID's in an array when the widget is created.
**
**--
*/
static void WidgetCreated ( w, tag )
Widget *w;
int *tag;
{
WidgetID[ *tag ] = w;
}
/*============================================================================*/
/* Set Up Module */
/* */
/* This routine does the initial set-up necessary to access GKS: open */
/* GKS, open the workstation, activate the workstation, and establish */
/* the workstation window & viewport */
/*============================================================================*/
set_up ( wsid_ptr, largest_viewport_ptr, ratio_x_ptr, ratio_y_ptr,
ws_type_ptr, conid_ptr )
int *wsid_ptr,
*largest_viewport_ptr,
*ws_type_ptr;
float *ratio_x_ptr,
*ratio_y_ptr;
struct dsc$descriptor_s *conid_ptr; /* !!! */
{
int error_status,
category,
item_data_length,
dummy_int,
def_mode, regen_flag;
float display_x, display_y,
min_display_x, min_display_y,
max_display_x, max_display_y;
$DESCRIPTOR (error_file, "sys$error:");
$DESCRIPTOR (dummy_dsc, "dsc$descriptor_s");
/******************************************************************************/
/* open GKS */
/******************************************************************************/
gks$open_gks ( &error_file );
/******************************************************************************/
/* check the workstation category; if it is not OUTIN, then abort */
/******************************************************************************/
/* gks$inq_ws_category ( &GKS$K_WSTYPE_DEFAULT, &error_status, &category);*/
/* check the widget one - not just the default !!! */
gks$inq_ws_category ( &GKS$K_DECWINDOWS_WIDGET, &error_status, &category);
/* if ( category != GKS$K_WSCAT_OUTIN )
{
printf ("\n The workstation type is not OUTIN; program aborting");
return 1;
} */
/******************************************************************************/
/* open & activate the workstation */
/******************************************************************************/
/* gks$open_ws ( wsid_ptr, &GKS$K_CONID_DEFAULT,
&GKS$K_WSTYPE_DEFAULT ); */
gks$open_ws ( wsid_ptr, conid_ptr, &GKS$K_DECWINDOWS_WIDGET );
gks$activate_ws ( wsid_ptr );
/******************************************************************************/
/* get the workstation type; this information is needed for the call */
/* to gks$inq_max_ds_size */
/******************************************************************************/
gks$inq_ws_type ( wsid_ptr, &error_status, &dummy_dsc, ws_type_ptr,
&dummy_int);
if ( error_status != GKS$_SUCCESS )
{
printf("\n Error checking workstation type; error: %d",error_status);
return 1;
}
/******************************************************************************/
/* make sure that the deferral mode and regeneration flag are properly */
/* set. */
/******************************************************************************/
/* gks$inq_def_defer_state ( ws_type_ptr, &error_status, &def_mode,
®en_flag );
if ( error_status != GKS$_SUCCESS )
{
printf("\n Error checking defer state; error: %d",error_status);
return 1;
} */
/******************************************************************************/
/* defer output as long as possible and suppress implicit regenerations */
/******************************************************************************/
/* if ( ( def_mode != GKS$K_ASTI ) ||
( regen_flag != GKS$K_IRG_SUPPRESSED ))
{
gks$set_defer_state ( wsid_ptr, &GKS$K_ASTI, &GKS$K_IRG_SUPPRESSED);
} */
/******************************************************************************/
/* check the maximum X & Y for this device */
/******************************************************************************/
gks$inq_max_ds_size ( ws_type_ptr, &error_status, &dummy_int,
&display_x, &display_y, &dummy_int,
&dummy_int);
if ( error_status != GKS$_SUCCESS)
{
printf("\n Error checking max_ds_size; error: %d",error_status);
return 1;
}
printf("\n max_display_x: %f max_display_y: %f",display_x,display_y);
/******************************************************************************/
/* Calculate the normalized display ratio based on the physical device */
/* size */
/******************************************************************************/
/* display_x = 900;
display_y = 800; */
*ratio_y_ptr = ( ( display_x > display_y ) ?
( display_y / display_x ) : 1.0 );
*ratio_x_ptr = ( ( display_x > display_y) ?
1.0 : ( display_x / display_y ) );
gks$select_xform( largest_viewport_ptr );
/******************************************************************************/
/* use the UIL defined window as the viewport */
/******************************************************************************/
min_display_x = 0.0;
min_display_y = 0.0;
max_display_x = display_x;
max_display_y = display_y;
gks$set_ws_window ( wsid_ptr, &0.0, ratio_x_ptr, &0.0,
ratio_y_ptr );
gks$set_ws_viewport ( wsid_ptr, &min_display_x, &max_display_x,
&min_display_y, &max_display_y );
return 0;
}
/*============================================================================*/
/* Display Picture Module */
/* */
/* This routine sets the workstation window & viewport and displays the */
/* picture. */
/*============================================================================*/
display_pic ( wsid_ptr, largest_viewport_ptr, ratio_x_ptr, ratio_y_ptr,
ws_type_ptr )
int *wsid_ptr,
*largest_viewport_ptr,
*ws_type_ptr;
float *ratio_x_ptr,
*ratio_y_ptr;
{
float item1_x_13 = 0.228571,
item1_y_13 = 0.409524,
item1_x_11[5] = { 0.019048, 0.019048, 0.780952, 0.780952,
0.019048 },
item1_y_11[5] = { 0.019048, 0.590476, 0.590476, 0.019048,
0.019048 },
text_height = { 0.075561 },
linewidth = 1.966942;
int linetype = 1,
text_font_prec[1][2] = { -15, 2 };
float view_min_x, view_max_x, view_min_y, view_max_y,
win_min_x, win_max_x, win_min_y, win_max_y,
xform_matrix[6], xform_matrix2[6];
/*****************************************************************************/
/* set the window & viewport */
/*****************************************************************************/
win_min_x = 0.0;
win_max_x = MAX_X;
win_min_y = 0.0;
win_max_y = MAX_Y;
gks$set_window ( largest_viewport_ptr, &win_min_x, &win_max_x,
&win_min_y, &win_max_y);
view_min_x = 0.0;
view_max_x = *ratio_x_ptr;
view_min_y = 0.0;
view_max_y = *ratio_y_ptr;
gks$set_viewport ( largest_viewport_ptr, &view_min_x, &view_max_x,
&view_min_y, &view_max_y);
/*****************************************************************************/
/* create a segment and display all polylines, text and GDPs in this */
/* segment */
/*****************************************************************************/
set_transformation ( ratio_x_ptr, ratio_y_ptr, &xform_matrix2 );
gks$create_seg ( &1 );
gks$set_pline_linewidth ( &linewidth );
gks$set_pline_linetype ( &linetype );
gks$polyline ( &5, item1_x_11, item1_y_11 );
gks$set_text_height ( &text_height );
/* gks$set_text_fontprec ( &text_font_prec[1][0], &text_font_prec[1][1] ); */
gks$text ( &item1_x_13, &item1_y_13, &item1_text_13 );
gks$close_seg ( &1 );
return;
}
/*============================================================================*/
/* set segment transformation module */
/* */
/* create the segment transformation matrix */
/* use the center of the picture as the fixed point */
/* translate the center of the picture, to the center of the viewport */
/*============================================================================*/
set_transformation ( ratio_x_ptr, ratio_y_ptr, xform_matrix2_ptr )
float *ratio_x_ptr, *ratio_y_ptr,
*xform_matrix2_ptr;
{
float fixed_pt_x, fixed_pt_y,
scale_x, scale_y,
translation_x, translation_y,
zoom_x, zoom_y, zoom_factor,
xform_matrix[6];
fixed_pt_x = 0.0;
fixed_pt_y = 0.0;
scale_x = MAX_X / *ratio_x_ptr;
scale_y = MAX_Y / *ratio_y_ptr;
translation_x = (*ratio_x_ptr / 2.0) -
(((MAX_PIC_X - MIN_PIC_X) / 2.0) + MIN_PIC_X);
translation_y = (*ratio_y_ptr / 2.0) -
(((MAX_PIC_Y - MIN_PIC_Y) / 2.0) + MIN_PIC_Y);
gks$eval_xform_matrix ( &fixed_pt_x, &fixed_pt_y, &translation_x,
&translation_y, &0.0, &scale_x, &scale_y,
&GKS$K_COORDINATES_NDC, &xform_matrix );
fixed_pt_x = *ratio_x_ptr / 2.0;
fixed_pt_y = *ratio_y_ptr / 2.0;
zoom_x = *ratio_x_ptr / scale_x;
zoom_y = *ratio_y_ptr / scale_y;
if ( zoom_x > zoom_y )
zoom_factor = zoom_x;
else
zoom_factor = zoom_y;
gks$accum_xform_matrix ( &xform_matrix, &fixed_pt_x,
&fixed_pt_y, &0.0, &0.0, &0.0, &zoom_factor,
&zoom_factor, &GKS$K_COORDINATES_NDC, xform_matrix2_ptr );
return;
}
/*============================================================================*/
/* End Program Module */
/* */
/* This routine deactivates the workstation, closes the workstation */
/* and closes GKS */
/*============================================================================*/
end_program ( wsid_ptr )
int *wsid_ptr;
{
gks$deactivate_ws ( wsid_ptr );
/* gks$close_ws ( wsid_ptr ); */
gks$close_gks ( );
}
/******* Create color ************************/
static int doDefineColor(n)
{
int pixel;
XColor exact_color,screen_color;
char *colors[] = {
"dark slate blue",
"light grey",
"black"
};
if ((XDefaultVisualOfScreen(screen))->class == PseudoColor
|| (XDefaultVisualOfScreen(screen))->class == DirectColor)
if (XAllocNamedColor(dpy, XDefaultColormapOfScreen(screen),
colors[n-1], &screen_color, &exact_color))
return screen_color.pixel;
else
printf("Color not allocated!");
else
switch (n) {
case 1: return XBlackPixelOfScreen(screen); break;
case 2: return XWhitePixelOfScreen(screen); break;
case 3: return XBlackPixelOfScreen(screen); break;
}
}
|