Need something to fill your lunch/coffee break today?

The attached code crashes (SIGSEGV) with LT and works with Motif 2.0 ...

In XmString line 943 fontstruct seems to be 0x0 ...

-- 
Alexander Mai
[EMAIL PROTECTED]

/*
 * Include File Declarations
 */

#include <stdlib.h>
#include <stdio.h>
#include <Xm/MainW.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/RowColumn.h>
#include <Xm/PushBG.h>
#include <Xm/PushB.h>
#include <Xm/Scale.h>
#include <Xm/CascadeB.h>
#include <Xm/MessageB.h>

/*-------------------------------------------------------------
** Forward Declarations
*/

Widget CreateHelp ();
void HelpCB (Widget w, XtPointer client_data, XtPointer call_data);
Widget CreateHelp (Widget    parent);
void ScaleCallback (Widget sw, XtPointer closure, XtPointer call_data);

/*
 * Global Variables
 */

static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;

Widget appshell; 
Arg args [15];
int n;
int i;

/*-------------------------------------------------------------
**  HelpCB      - callback for help button
*/
void HelpCB (Widget    w,    /*  widget id    */
             XtPointer    client_data,  /*  data from application   */
             XtPointer    call_data  /*  data from widget class  */)
{
  Widget    message_box;    /*  message box    */


  /*  Create help window. */
  message_box = CreateHelp (w);


  /*  Display help window. */
  XtManageChild (message_box);
}

/*-------------------------------------------------------------
**  CreateHelp    - create help window
*/
Widget CreateHelp (Widget    parent)    /*  parent widget  */
{
  Widget    button;
  Widget    message_box;  /*  Message Dialog   */
  Arg    args[10];    /*  arg list    */
  register int  n;    /*  arg count    */

  static char  message[1000];  /*  help text  */
  XmString  title_string = NULL;
  XmString  message_string = NULL;
  XmString  button_string = NULL;

  /*  Generate message to display. */
  sprintf (message, "\
This program shows you how to create and use a scale widget.  When\n\
you move the slider, the values are displayed on the scale and a\n\
message appears on the terminal window with the callback reason and the\n\
new scale value.  To terminate the program, press the Exit button \n\
and then the Quit button.\0");

  /* Create the compound strings */
  message_string = XmStringCreateLtoR (message, charset);
  button_string = XmStringCreateLtoR ("Close", charset);
  title_string = XmStringCreateLtoR ("getdlog help", charset);

  /*  Create message box dialog. */
  n = 0;
  XtSetArg (args[n], XmNdialogTitle, title_string);  n++;
  XtSetArg (args[n], XmNokLabelString, button_string);  n++;
  XtSetArg (args[n], XmNmessageString, message_string);  n++;
  message_box = XmCreateMessageDialog (parent, "helpbox", args, n);

  button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
  XtUnmanageChild (button);
  button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
  XtUnmanageChild (button);

  /*  Free strings and return message box. */
  if (title_string) XtFree (title_string);
  if (message_string) XtFree (message_string);
  if (button_string) XtFree (button_string);
  return (message_box);
}

/*-------------------------------------------------------------
**  QuitCB      - callback for quit button
*/
void QuitCB (Widget    w,    /*  widget id    */
XtPointer    client_data,  /*  data from application   */
XtPointer    call_data  /*  data from widget class  */)
{

  /*  Terminate the application. */
  exit (0);
}


/* ScaleCallback is executed for any callback from scale.  The
   scale callback structure is used to find the callback reason and
   the scale value.  Control is switched based on the callback reason.
 *
 */
void ScaleCallback (
Widget sw,
XtPointer closure,
XtPointer call_data)

{
   int value;
   int reason;
   int pixel;
   XmScaleCallbackStruct * call_value = (XmScaleCallbackStruct *) call_data;
      

   reason = call_value -> reason;
   value = call_value -> value;


   switch (reason)
   {
      case XmCR_VALUE_CHANGED:
         printf ("Reason = XmCR_VALUE_CHANGED,  Value = %d\n", value);
      break;

      case XmCR_DRAG:
         printf ("Reason = XmCR_DRAG,   Value = %d\n", value);
      break;

      default:
         printf ("Hit the default, incorrect reason sent!!\n");
      break;

   }
}
/*
 *main
 */
int main(int argc, char *argv[])
{
  Widget  main_window, form, frame, menu_bar, menu_pane, cascade, button;
  XtAppContext app_context;
  Display *display;
   
  Widget scale;
  Widget label[11];
  XmFontList fontlist;
  XFontStruct * font;
  XmStringCharSet cset = XmSTRING_DEFAULT_CHARSET;
  XmString titleString;

/*
 * Initialize the application shell widget
 */
  appshell = XtAppInitialize(&app_context, "Getdlog", NULL, 0, &argc, argv,
  NULL, args, 0);

 /* Create main window.
 */
 n = 0;
 main_window = XmCreateMainWindow (appshell, "main1", args, n);
 XtManageChild (main_window);

 /* Create menu bar in main window. */
 n = 0;
 menu_bar = XmCreateMenuBar (main_window, "menu_bar", args, n); 
 XtManageChild (menu_bar);

 /* Create Exit pulldown menu. */
 n = 0;
 menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n);

 n = 0;
 button = XmCreatePushButtonGadget (menu_pane, "Quit", args, n);
 XtManageChild (button);
 XtAddCallback (button, XmNactivateCallback, QuitCB, NULL);

 n = 0;
 XtSetArg (args[n], XmNsubMenuId, menu_pane); n++;
 cascade = XmCreateCascadeButton (menu_bar, "Exit", args, n);
 XtManageChild (cascade);

 /* Create "Help" button. */
 n = 0;
 cascade = XmCreateCascadeButton (menu_bar, "Help", args, n);
 XtManageChild (cascade);
 XtAddCallback (cascade, XmNactivateCallback, HelpCB, NULL);

 n = 0;
 XtSetArg (args[n], XmNmenuHelpWidget, cascade); n++;
 XtSetValues (menu_bar, args, n);

 i = 0; 
    
/*
 *Create a form widget 
 */
 i = 0;
 form = XmCreateForm (main_window, "form", args, i);

/*
 *Manage the form widget 
 */
  XtManageChild(form);

/*
 * Set main window areas 
 */
  XmMainWindowSetAreas (main_window, menu_bar, NULL, NULL, NULL, form);

/*
 *Create a frame widget to enhance the scale's appearance 
 */
  i = 0;
  XtSetArg (args[i], XmNbottomOffset, 15); i++;
  XtSetArg (args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  XtSetArg (args[i], XmNtopOffset, 15); i++;
  XtSetArg (args[i], XmNtopAttachment, XmATTACH_FORM); i++;
  XtSetArg (args[i], XmNleftOffset, 15); i++;
  XtSetArg (args[i], XmNleftAttachment, XmATTACH_FORM); i++;
  XtSetArg (args[i], XmNrightOffset, 15); i++;
  XtSetArg (args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  XtSetArg (args[i], XmNmarginHeight, 10); i++;
  XtSetArg (args[i], XmNmarginWidth, 10); i++;
  frame = XmCreateFrame (form, "frame", args, i);

/*
 *Manage the frame widget 
 */
  XtManageChild(frame);

/*
 *Create a compound string for the scale title 
 */
   font = XLoadQueryFont (XtDisplay (appshell), "courB14");
   fontlist = XmStringCreateFontList (font, cset);
   titleString = XmStringCreateLtoR ("Scale Demonstration", cset);

/* 
 *Set up arglist and create the scale  
 */
   n = 0;
   XtSetArg (args[n], XmNfontList, fontlist);   n++; 
   XtSetArg (args[n], XmNshowValue, True);      n++; 
   XtSetArg (args[n], XmNtitleString, titleString); n++;
   XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
   XtSetArg (args[n], XmNmaximum, 100); n++;
   XtSetArg (args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
   scale = XmCreateScale(frame, "scale", args, n); 
   XmStringFree (titleString);

/*
 *Manage the scale 
 */
   XtManageChild (scale);

/*
 *Add the callbacks 
 */
   XtAddCallback (scale, XmNvalueChangedCallback, ScaleCallback, NULL);
   XtAddCallback (scale, XmNdragCallback,         ScaleCallback, NULL);

/*
 * Set fontlist for all the labels 
 */
   n = 0;
   XtSetArg (args[0], XmNfontList, fontlist); n++;      

/*
 *Create the labels for the scale values 
 */
   i = 0;
   label[i] = XmCreateLabel (scale, "0", args, n); i++;
   label[i] = XmCreateLabel (scale, "10", args, n); i++;
   label[i] = XmCreateLabel (scale, "20", args, n); i++;
   label[i] = XmCreateLabel (scale, "30", args, n); i++;
   label[i] = XmCreateLabel (scale, "40", args, n); i++;
   label[i] = XmCreateLabel (scale, "50", args, n); i++;
   label[i] = XmCreateLabel (scale, "60", args, n); i++;
   label[i] = XmCreateLabel (scale, "70", args, n); i++;
   label[i] = XmCreateLabel (scale, "80", args, n); i++;
   label[i] = XmCreateLabel (scale, "90", args, n); i++;
   label[i] = XmCreateLabel (scale, "100", args, n); i++;

/*
 * Manage all the labels 
 */
  XtManageChildren (label,i);
  XmFontListFree (fontlist);

/*
 * Realize the appshell widget, which displays all children
 */ 
  XtRealizeWidget(appshell);

/*
 * Go into a loop and wait for input
 */
  XtAppMainLoop(app_context);

  exit(0);
}

Reply via email to