[ale] Motif (Moo-Tiff) Programming Question (_detailed_, sorry)

John M. Mills jmills at siberia.gtri.gatech.edu
Wed Oct 16 11:30:37 EDT 1996


Greetings -- Hope there's a Motifer or two out there.

I am having trouble setting the argument XmNdialogTitle in a message dialog
widget.  If I don't set the title, the frame comes up labled:
 "<widget_name>_popup" and I want functional names.  A short example
modified from ch.7 of Doug Young's book is appended below.  If the line:
    XtSetArg (args[n], XmNdialogTitle, dialog_title); n++;
is executed, I get a segfault.  O'Reilly has similar examples in their
Motif 1.2 book which show the same behavior.

Parameters: Moo-Tiff clone of OSF/Motif2.0, a.out, gcc 2.6.3, Linux 1.2.13
In my environment, I have:
$env
[...]
XFONTPATH=/usr/X11/lib/fonts:/usr/X11/lib/X11/fonts
XmFONTLIST_DEFAULT_TAG=-adobe-helvetica-bold-o-normal--14-100-100-100-p-82-iso8859-1
[...]

I hope someone can see what's going wrong by looking at the source.  The
killer argument is in line 102, and the proc faults when you create the
widget with that argument.

If you want to build the example, you will also need the library source,
part of the entire source tree from ftp.x.org in:
    contrib/book_examples/young2.mot
This is a *.tar..Z file, and you may need to rename it in order to unpack it.
I patched the makefiles just to add my -I's to CFLAGS and my -L's to LIBS.

Thanks for any suggestions.  

******************************Here's the Smut********************************
/********************************************************************
 *         This example code is from the book:
 *
 *           The X Window System: Programming and Applications with Xt
 *           Second OSF/Motif Edition
 *         by
 *           Douglas Young
 *           Prentice Hall, 1994
 *
 *         Copyright 1994 by Prentice Hall
 *         All Rights Reserved
 *
 *  Permission to use, copy, modify, and distribute this software for 
 *  any purpose except publication and without fee is hereby granted, provided 
 *  that the above copyright notice appear in all copies of the software.
 * *****************************************************************************
/*******************************************************************************
 * Example customdialog2.c modified by j.m.mills to show XmNdialogTitle problem
 *******************************************************************************/
/***************************************************
 * customdialog.c: Demonstrate a custom dialog
 ***************************************************/
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/RowColumn.h>
#include <Xm/TextF.h>
#include <Xm/PushB.h>
#include <Xm/MessageB.h>

Widget CreateDialog ( Widget parent, char *name, 
                      XtCallbackProc OkCallback,
                      XtCallbackProc ApplyCallback,
                      XtCallbackProc CancelCallback );

static void ShowDialogCallback ( Widget    w, 
                                 XtPointer clientData, 
                                 XtPointer callData )
{
    Widget     dialog = ( Widget ) clientData;

    XtManageChild ( dialog );
}

void main ( int argc, char **argv )
{
    Widget       shell, button, dialog;
    XtAppContext app;

   /*
    * Initialize Xt
    */

    shell = XtAppInitialize ( &app, "Customdialog", NULL, 0, 
                              &argc, argv, NULL, NULL, 0 );
    
    button = XtCreateManagedWidget ( "button", xmPushButtonWidgetClass,
                                     shell, NULL, 0);

   /*
    * Create a popup dialog and a register a callback
    * function to display the dialog when the button is activated.
    */

    dialog = CreateDialog ( button, "Dialog" , NULL, NULL, NULL );

    XtAddCallback ( button, XmNactivateCallback, 
                    ShowDialogCallback, dialog );
    
    XtRealizeWidget ( shell );
    XtAppMainLoop ( app );
}
                    
const char *fields[] = {"Name", "Address", "Phone"};

typedef struct {
    Widget name, addr, phone;
} DialogWidgets;

Widget CreateDialog ( Widget parent, char *name, 
                      XtCallbackProc OkCallback,
                      XtCallbackProc ApplyCallback,
                      XtCallbackProc CancelCallback )
{
    Widget dialog, rc, apply;
    int    i;
    DialogWidgets *widgets;
    Arg args[10];
    int n;
    char dialog_title[] = "this widget";
    XmString title_string;

    widgets = ( DialogWidgets * ) XtMalloc ( sizeof ( DialogWidgets ) );
    

   /*
    * Create a standard message dialog
    */

    title_string = XmStringCreateLocalized(dialog_title);
    n = 0;
    /****** Next line causes segfault at run time *****/
    XtSetArg (args[n], XmNdialogTitle, dialog_title); n++;
    dialog = XmCreateMessageDialog ( parent, name, args, n );

   /*
    * Remove unwanted children
    */

    XtUnmanageChild ( XmMessageBoxGetChild ( dialog, 
                                             XmDIALOG_SYMBOL_LABEL ) );
    XtUnmanageChild ( XmMessageBoxGetChild ( dialog,
                                             XmDIALOG_MESSAGE_LABEL ) );

   /*
    * Add an apply button if there is a callback
    */

    if ( ApplyCallback )
       apply = XtCreateManagedWidget ( "apply", xmPushButtonWidgetClass,
                                       dialog, NULL, 0 );
   /*
    * Add callbacks. Note different treatment of apply button
    */

    if ( OkCallback )
        XtAddCallback ( dialog, XmNokCallback,
                        OkCallback, widgets );
    if ( CancelCallback )
        XtAddCallback ( dialog, XmNokCallback, 
                        CancelCallback,widgets );
    if ( ApplyCallback )
        XtAddCallback ( apply, XmNactivateCallback,
                        ApplyCallback, widgets );

   /* 
    * Create a manager widget to handle the dialog layout
    */

    rc = XtVaCreateManagedWidget ( "rc", xmRowColumnWidgetClass, dialog,
                                   XmNnumColumns,  2, 
                                   XmNpacking,     XmPACK_COLUMN, 
                                   XmNorientation, XmVERTICAL, 
                                   NULL );
   /*
    * Create the labels
    */

    XtCreateManagedWidget ( "Name", xmLabelWidgetClass, rc, NULL, 0 );
    XtCreateManagedWidget ( "Address", xmLabelWidgetClass, 
                            rc, NULL, 0 );
    XtCreateManagedWidget ( "Phone", xmLabelWidgetClass, 
                            rc, NULL, 0 );

   /*
    * Create the text input field
    */

    widgets->name = XtCreateManagedWidget ( "name",
                                            xmTextFieldWidgetClass,
                                            rc, NULL, 0);
    widgets->addr = XtCreateManagedWidget ( "addr",
                                            xmTextFieldWidgetClass,
                                            rc, NULL, 0);
    widgets->phone = XtCreateManagedWidget ( "phone",
                                             xmTextFieldWidgetClass,
                                             rc, NULL, 0);

    return dialog;
}






More information about the Ale mailing list