[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | "OSF/Motif" is a trademark |
Notice: | MOTIF kit note in 7.* |
Moderator: | GOOEY::GRASS |
|
Created: | Mon Aug 07 1989 |
Last Modified: | Thu Jun 05 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 5973 |
Total number of notes: | 24620 |
5938.0. "Problem XmListGetMatchPos" by TKTV20::MATUZAKI () Thu Mar 06 1997 23:44
I have a question about XmListGetMatchPos routine.
It not get position count of a compound string.
XmListGetSelectedPos & XmStringCompare is OK.
Digital UNIX Version is 4.0A, 4.0, 3.2G..
Thank in advance for your help.
Flowing program:
----------------------------------------------------------------------------
/* SBOX.H */
/* */
/* Include file from VUIT */
/* 1. VUIT global routine declarations */
/* 2. Global variables */
/* 3. Literals from UIL code */
/* VUIT routines for the user to call */
void s_error();
int HashFunction();
int HashLookup();
int HashRegister();
void VUIT_Manage();
void VUIT_Unmanage();
/* Motif Global variables */
Display *display; /* Display variable */
XtAppContext app_context; /* application context */
Widget toplevel_widget; /* Root widget ID of application */
MrmHierarchy s_MrmHierarchy; /* MRM database hierarchy ID */
------------------------------------------------------------------------------
SBOX.C
#include <stdio.h> /* For printf and so on. */
#include <Xm/Text.h>
#include <Mrm/MrmAppl.h> /* Motif Toolkit and MRM */
#include <X11/X.h>
/* The vuit generated application include file. */
/* If the user does not specify a directory for the file */
/* then the vaxc$include logical needs to be defined to point to the */
/* directory of the include file. */
#include "SBOX.h"
/* Global data */
static MrmType class_id; /* Place to keep class ID*/
static MrmType *dummy_class; /* and class variable. */
static char *db_filename_vec[] = /* Mrm.hierachy file list. */
{
"SBOX.uid"
};
static int db_filename_num =
(sizeof db_filename_vec / sizeof db_filename_vec [0]);
char *vuit_dummy_ident_value = "VUIT dummy identifier value";
int i;
#define hash_table_limit 500
struct HASH_TABLE_STRUCT
{
char *widget_name;
Widget id;
} hash_table[hash_table_limit + 1];
/*
* Forward declarations
*/
void okCb();
void cancelCb();
/*
* Names and addresses of callback routines to register with Mrm
*/
static MrmRegisterArg reglist [] = {
{"okCb", (caddr_t)okCb},
{"cancelCb", (caddr_t)cancelCb}};
static int reglist_num = (sizeof reglist / sizeof reglist[0]);
unsigned int main(argc, argv)
unsigned int argc; /* Command line argument count. */
char *argv[]; /* Pointers to command line args. */
{
Arg arglist[2];
int n;
MrmInitialize(); /* Initialize MRM before initializing */
/* the X Toolkit. */
DXmInitialize(); /* Initialize additional DEC widgets */
/*
* If we had user-defined widgets, we would register them with Mrm.here.
*/
/*
* Initialize the X Toolkit. We get back a top level shell widget.
*/
XtToolkitInitialize();
app_context = XtCreateApplicationContext();
display = XtOpenDisplay(app_context, NULL, argv[0], "example",
NULL, 0, &argc, argv);
if (display == NULL)
{
fprintf(stderr, "%s: Can't open display\n", argv[0]);
exit(1);
}
n = 0;
XtSetArg(arglist[n], XmNallowShellResize, True); n++;
toplevel_widget = XtAppCreateShell(argv[0], NULL,
applicationShellWidgetClass, display, arglist, n);
/*
* Open the UID files (the output of the UIL compiler) in the hierarchy
*/
if (MrmOpenHierarchy(db_filename_num, /* Number of files. */
db_filename_vec, /* Array of file names. */
NULL, /* Default OS extenstion. */
&s_MrmHierarchy) /* Pointer to returned MRM ID */
!=MrmSUCCESS)
s_error("can't open hierarchy");
MrmRegisterNames (reglist, reglist_num);
VUIT_Manage("mainw");
/*
* Realize the top level widget. All managed children now become visible
*/
XtRealizeWidget(toplevel_widget);
/*
* Sit around forever waiting to process X-events. We never leave
* XtAppMainLoop. From here on, we only execute our callback routines.
*/
XtAppMainLoop(app_context);
}
/*
* All errors are fatal.
*/
void s_error(problem_string)
char *problem_string;
{
printf("%s\n", problem_string);
exit(0);
}
void VUIT_Manage(widget_name)
char *widget_name;
{
Widget id;
Window pop_window;
XWindowChanges values;
if (HashLookup(widget_name, &id))
if (XtIsManaged(id))
{
pop_window = XtWindow(XtParent(id));
values.x = values.y = values.width = values.height =
values.border_width = values.sibling = NULL;
values.stack_mode = Above;
XConfigureWindow(display, pop_window, CWStackMode, &values);
}
else
XtManageChild(id);
else
{
MrmFetchWidget(s_MrmHierarchy, widget_name, toplevel_widget, &id,
&class_id);
XtManageChild(id);
HashRegister(widget_name, id);
}
}
void VUIT_Unmanage(widget_name)
char *widget_name;
{
Widget id;
if (HashLookup(widget_name, &id))
XtUnmanageChild(id);
}
int HashRegister (widget_name, id)
char *widget_name;
Widget id;
{
int ndx;
for (ndx = HashFunction(widget_name, hash_table_limit);
((hash_table[ndx].widget_name != NULL) &&
(ndx < hash_table_limit));
ndx++);
if (hash_table[ndx].widget_name != NULL)
for (ndx = 0;
hash_table[ndx].widget_name != NULL;
ndx++);
if (ndx > hash_table_limit)
return (FALSE);
else
{
hash_table[ndx].widget_name = XtCalloc(1, strlen(widget_name) + 1);
strcpy(hash_table[ndx].widget_name, widget_name);
hash_table[ndx].id = id;
return (TRUE);
}
}
int HashLookup (name, id)
char *name;
Widget *id;
{
int ndx;
for (ndx = HashFunction(name, hash_table_limit);
((hash_table[ndx].widget_name != NULL) &&
(ndx <= hash_table_limit));
ndx++)
if (strcmp(name, hash_table[ndx].widget_name) == 0)
{
*id = hash_table[ndx].id;
return (TRUE);
}
if (ndx > hash_table_limit)
for (ndx = 0;
((hash_table[ndx].widget_name != NULL) &&
(ndx <= hash_table_limit));
ndx++)
{
if (strcmp(name, hash_table[ndx].widget_name) == 0)
{
*id = hash_table[ndx].id;
return (TRUE);
}
}
return (FALSE);
}
int HashFunction (name, max)
char *name;
int max;
{
#define HashVecSize 20 /* plenty for 31 character names */
typedef union
{
short int intname[HashVecSize]; /* name as vector of ints */
char charname[2*HashVecSize]; /* name as vector of chars */
} HashName;
HashName locname; /* aligned name */
int namelen; /* length of name */
int namelim; /* length limit (fullword size) */
int namextra; /* limit factor remainder */
int code = 0; /* hash code value */
int ndx; /* loop index */
/*
* Copy the name into the local aligned union.
* Process the name as a vector of integers, with some remaining character
* The string is copied into a local union in order to force correct
* alignment for alignment-sensitive processors.
*/
strcpy (locname.charname, name);
namelen = strlen (locname.charname);
namelim = namelen >> 1; /* divide by 2 */
namextra = namelen & 1; /* remainder */
/*
* XOR each integer part of the name together, followed by the trailing
* 0/1 character
*/
for ( ndx=0 ; ndx<namelim ; ndx++ )
code = code ^ ((locname.intname[ndx])<<ndx);
if ( namextra > 0 )
code = code ^ ((locname.intname[ndx])&0x00FF);
return (code&0x7FFF) % max;
}
Widget list, form_widget;
void okCb (w, tag, reason)
Widget w;
int *tag;
unsigned long *reason;
{
XmString xms, xms2; int *pos_list, pos_count, n; Arg rargs[1];
static XmStringContext context = 0; char *text; XmStringCharSet charset;
XmStringDirection direction; Boolean separator;
n = 0;
XtSetArg(rargs[n], XmNtextString, &xms); n++;
XtGetValues(w, rargs, n);
/* let's see what the compound string looks like, okay ? */
if (XmStringInitContext(&context, xms))
if (XmStringGetNextSegment(context, &text, &charset, &direction,
&separator))
printf("text = %s, charset = %d, direction = %d\n",
text, charset, direction);
XmStringFreeContext(context);
xms2 = XmStringCreateSimple(text);
XtFree(text);
/* Compare the two compound strings
if (XmStringByteCompare(xms, xms2))
*/ if (XmStringCompare(xms, xms2))
printf("Compound strings match\n");
else
printf("Compound strings do not match\n");
XmStringFree(xms2);
list = XmSelectionBoxGetChild(w, XmDIALOG_LIST);
if (XmListGetMatchPos(list, xms, &pos_list, &pos_count) == TRUE)
printf("Number of elements that matched = %d\n", pos_count);
else
printf("No match\n");
XmStringFree(xms);
}
void cancelCb (w, tag, reason)
Widget w;
int *tag;
unsigned long *reason;
{
exit(1);
}
-----------------------------------------------------------------------------
SBOX.uil
module SBOX
!***VUIT_Generate_Callback_Tags ***
names = case_sensitive
object
!***VUIT_Generate_Callback_Tags ***
mainw: XmMainWindow
{
arguments
{
XmNx = 48;
XmNy = 181;
XmNborderWidth = 1;
XmNwidth = 365;
XmNheight = 305;
};
controls
{
XmSelectionBox sbox;
};
};
sbox: XmSelectionBox
{
arguments
{
XmNx = 214;
XmNy = 67;
XmNborderWidth = 1;
XmNlistItems = string_table(
compound_string("first item", character_set = iso_latin1),
compound_string("second item ", character_set = iso_latin1),
compound_string("third item ", character_set = iso_latin1),
compound_string("fourth item ", character_set = iso_latin1),
compound_string("fifth item", character_set = iso_latin1),
compound_string("sixth item", character_set = iso_latin1));
};
callbacks
{
XmNokCallback = procedures
{
okCb(0);
};
XmNcancelCallback = procedures
{
cancelCb(0);
};
};
};
procedure
okCb;
cancelCb;
end module;
T.R | Title | User | Personal Name | Date | Lines
|
---|