remove all Xt/X11/Motif code in FileIO.c

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@430 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-14 08:22:59 +00:00
parent 174a84b4db
commit 76034f3d9f
13 changed files with 469 additions and 394 deletions

View File

@ -47,6 +47,7 @@
#include "RegWindow.h"
#include "TextBox.h"
#include "util.h"
#include "xtutil.h"
typedef struct _accwindow {
/* The account type buttons: */

View File

@ -40,6 +40,7 @@
#include "RegWindow.h"
#include "RecnWindow.h"
#include "util.h"
#include "xtutil.h"
/** GLOBALS *********************************************************/

View File

@ -30,6 +30,7 @@
#include "FileBox.h"
#include "main.h"
#include "util.h"
#include "xtutil.h"
/** GLOBALS *********************************************************/
extern XtAppContext app;

View File

@ -79,12 +79,12 @@
#include <fcntl.h>
#include <unistd.h>
#include <Xm/Xm.h>
#include "config.h"
#include "Account.h"
#include "Data.h"
#include "FileIO.h"
#include "main.h"
#include "util.h"
@ -94,12 +94,13 @@
#define VERSION 4
/** GLOBALS *********************************************************/
extern Widget toplevel;
static AccountGroup *holder; /* temporary holder for
* unclassified accounts */
static AccountGroup *maingrp; /* temporary holder for file
* being read */
static int error_code=0; /* error code, if error occurred */
static AccountGroup *holder; /* temporary holder for
* unclassified accounts */
static AccountGroup *maingrp; /* temporary holder for file
* being read */
/** PROTOTYPES ******************************************************/
static Account *locateAccount (int acc_id);
@ -119,6 +120,13 @@ static int writeSplit( int fd, Split *split);
static int writeString( int fd, char *str );
static int writeDate( int fd, Date *date );
/*******************************************************/
int xaccGetFileIOError (void)
{
return error_code;
}
/*******************************************************/
/* some endian stuff */
@ -193,12 +201,12 @@ xaccReadData( char *datafile )
char buf[BUFSIZE];
maingrp = 0x0;
error_code = ERR_FILEIO_NO_ERROR;
fd = open( datafile, RFLAGS, 0 );
if( fd == -1 )
if( fd == -1 )
{
sprintf (buf, FILE_NOT_FOUND_MSG, datafile);
errorBox (toplevel, buf);
error_code = ERR_FILEIO_FILE_NOT_FOUND;
return NULL;
}
@ -206,8 +214,7 @@ xaccReadData( char *datafile )
err = read( fd, &token, sizeof(int) );
if( sizeof(int) != err )
{
sprintf (buf, FILE_EMPTY_MSG, datafile);
errorBox (toplevel, buf);
error_code = ERR_FILEIO_FILE_EMPTY;
close(fd);
return NULL;
}
@ -216,19 +223,15 @@ xaccReadData( char *datafile )
/* If this is an old file, ask the user if the file
* should be updated */
if( VERSION > token ) {
if( !verifyBox( toplevel, FILE_TOO_OLD_MSG ) ) {
close(fd);
return NULL;
}
error_code = ERR_FILEIO_FILE_TOO_OLD;
}
/* If this is a newer file than we know how to deal
* with, warn the user */
if( VERSION < token ) {
if( !verifyBox( toplevel, FILE_TOO_NEW_MSG ) ) {
close(fd);
return NULL;
}
error_code = ERR_FILEIO_FILE_TOO_NEW;
close(fd);
return NULL;
}
holder = mallocAccountGroup();
@ -239,17 +242,14 @@ xaccReadData( char *datafile )
* error, try to continue anyway. */
num_unclaimed = xaccGetNumAccounts (holder);
if (num_unclaimed) {
if ( !verifyBox( toplevel, FILE_BAD_READ_MSG ) ) {
freeAccountGroup (holder);
freeAccountGroup (grp);
grp = NULL;
} else {
/* create a lost account, put the missing accounts there */
Account *acc = mallocAccount();
acc -> accountName = XtNewString (LOST_ACC_STR);
acc -> children = (struct _account_group *) holder;
insertAccount (grp, acc);
}
Account *acc;
error_code = ERR_FILEIO_FILE_BAD_READ;
/* create a lost account, put the missing accounts there */
acc = mallocAccount();
acc -> accountName = XtNewString (LOST_ACC_STR);
acc -> children = (struct _account_group *) holder;
insertAccount (grp, acc);
} else {
freeAccountGroup (holder);
holder = NULL;

View File

@ -40,17 +40,18 @@
# include <X11/xpm.h>
#endif
#include "main.h"
#include "util.h"
#if USE_HTMLW
#include "HTML.h"
#include <HTML.h>
#endif
#if USE_XMHTML
#include "XmHTML.h"
#include <XmHTML.h>
#endif
#include "main.h"
#include "util.h"
#include "xtutil.h"
/********************************************************************\
* HTML History functions *

View File

@ -912,20 +912,54 @@ fileMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
}
newfile = fileBox(toplevel,OPEN, "*.xac");
if (newfile) {
int io_error;
char buf[BUFSIZE];
AccountGroup *newgrp;
datafile = newfile;
/* destroy open windows first, before destroying the group itself */
xaccGroupWindowDestroy (grp);
freeAccountGroup (grp);
/* load the accounts from the users datafile */
grp = xaccReadData (datafile);
if( NULL == grp ) {
/* the file could not be found */
grp = mallocAccountGroup();
newgrp = xaccReadData (datafile);
/* check for i/o error, put up appropriate error message */
io_error = xaccGetFileIOError();
switch (io_error) {
case ERR_FILEIO_NO_ERROR:
break;
case ERR_FILEIO_FILE_NOT_FOUND:
sprintf (buf, FILE_NOT_FOUND_MSG, datafile);
errorBox (toplevel, buf);
break;
case ERR_FILEIO_FILE_EMPTY:
sprintf (buf, FILE_EMPTY_MSG, datafile);
errorBox (toplevel, buf);
break;
case ERR_FILEIO_FILE_TOO_NEW:
errorBox (toplevel, FILE_TOO_NEW_MSG);
break;
case ERR_FILEIO_FILE_TOO_OLD:
if (!verifyBox( toplevel, FILE_TOO_OLD_MSG )) {
freeAccountGroup (newgrp);
newgrp = NULL;
}
break;
case ERR_FILEIO_FILE_BAD_READ:
if (!verifyBox( toplevel, FILE_BAD_READ_MSG )) {
freeAccountGroup (newgrp);
newgrp = NULL;
}
break;
default:
break;
}
/* if we managed to read something, then go display it */
if (newgrp) {
/* destroy open windows first, before destroying the group itself */
xaccGroupWindowDestroy (grp);
freeAccountGroup (grp);
topgroup = newgrp;
}
topgroup = grp;
}
break;
}

View File

@ -55,7 +55,7 @@ SRCS = AccWindow.c Account.c AccountMenu.c Action.c AdjBWindow.c \
BuildMenu.c Data.c Destroy.c FileBox.c FileIO.c HelpWindow.c \
LedgerUtils.c MainWindow.c PopBox.c QIFIO.c QuickFill.c \
RecnWindow.c RegWindow.c Reports.c TextBox.c Transaction.c \
XferBox.c XferWindow.c date.c main.c util.c
XferBox.c XferWindow.c date.c main.c util.c xtutil.c
# OBJS = ${SRCS:.c=.o} $(LIBHTMLW) $(LIBXBAE) $(LIBCOMBO)
OBJS = ${SRCS:.c=.o} $(LIBXMHTML) $(LIBXBAE) $(LIBCOMBO)
######################################################################

View File

@ -41,6 +41,7 @@
#include "MainWindow.h"
#include "main.h"
#include "util.h"
#include "xtutil.h"
/** STRUCTS *********************************************************/
typedef struct _RecnWindow

View File

@ -35,6 +35,7 @@
#include "main.h"
#include "Reports.h"
#include "util.h"
#include "xtutil.h"
/********************************************************************\

View File

@ -40,6 +40,7 @@
#include "config.h"
#include "main.h"
#include "util.h"
#include "xtutil.h"
/********************************************************************\
**************** TEXTBOX STUFF *************************************

View File

@ -42,6 +42,7 @@
#include "RecnWindow.h"
#include "RegWindow.h"
#include "util.h"
#include "xtutil.h"
typedef struct _menuData

View File

@ -23,19 +23,6 @@
* Huntington Beach, CA 92648-4632 *
\********************************************************************/
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <Xm/Xm.h>
#include <Xm/Text.h>
#include <Xm/PanedW.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/DialogS.h>
#include <Xm/RowColumn.h>
#include <Xm/MessageB.h>
#include <Xbae/Matrix.h>
#include "config.h"
#include "main.h"
#include "util.h"
@ -43,9 +30,6 @@
/** GLOBALS *********************************************************/
int loglevel = 1;
extern XtAppContext app;
extern int realized;
/********************************************************************\
* DEBUGGING MEMORY ALLOCATION STUFF *
\********************************************************************/
@ -124,337 +108,5 @@ char * xaccPrintAmount (double val, short shrs)
return buf;
}
/********************************************************************\
* dateCB -- ensures the data the user enters in the date field *
* is in a valid format. *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - the callback struct *
* Return: none *
\********************************************************************/
void
dateCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)cb;
char input;
/* TODO: ??? add support for date field accelerator keys!! */
if( cbs->text->ptr != NULL )
{
input = (cbs->text->ptr)[0];
switch( input )
{
case '/':
/* Make sure that there is at most two '/' */
{
String str = XmTextGetString(mw);
int i,count=0;
for( i=0; str[i] != '\0'; i++ )
if( str[i] == '/' )
count++;
if( count >= 2 )
cbs->doit = False;
}
break;
case 0x0:
/* if delete key (for example) is hit, then input string */
/* will be an empty string. In such a case, allow the input */
cbs->doit = True;
break;
default:
/* only accept the input if it is a number */
cbs->doit = isNum(input);
}
}
}
/********************************************************************\
* amountCB -- ensures the data entered in the amount field is in *
* a valid format. *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - the callback struct *
* Return: none *
\********************************************************************/
void
amountCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)cb;
char input;
if( cbs->text->ptr != NULL )
{
input = (cbs->text->ptr)[0];
switch( input )
{
case '.':
/* Make sure that there is only one '.' */
{
String str = XmTextGetString(mw);
int i,count=0;
for( i=0; str[i] != '\0'; i++ )
if( str[i] == '.' )
count++;
if( count >= 1 )
cbs->doit = False;
}
break;
default:
/* only accept the input if it is a number */
cbs->doit = isNum(input);
}
}
}
/********************************************************************\
* noeditCB *
* makes an Xbae matrix non-editable *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - *
* Return: none *
\********************************************************************/
void
noeditCB( Widget mw, XtPointer cd, XtPointer cb )
{
XbaeMatrixEnterCellCallbackStruct *cbs =
(XbaeMatrixEnterCellCallbackStruct * )cb;
cbs->doit = False;
}
/********************************************************************\
* destroyShellCB *
* a callback to destroy a widget (cd, not w, because we want to *
* destroy a window, not a button!) *
* *
* Args: mw - the widget that called us *
* cd - the widget to destroy *
* cb - *
* Return: none *
\********************************************************************/
void
destroyShellCB( Widget w, XtPointer cd, XtPointer cb )
{
Widget window = (Widget)cd;
XtDestroyWidget(window);
}
/********************************************************************\
* setBusyCursor *
* sets the cursor to the busy watch *
* *
* Args: w - the widget over which to make cursor busy *
* Return: none *
\********************************************************************/
void
setBusyCursor( Widget w )
{
if( realized )
{
static Cursor watch = 0;
if( watch == 0 )
watch = XCreateFontCursor(XtDisplay(w),XC_watch);
XDefineCursor(XtDisplay(w),XtWindow(w),watch);
XmUpdateDisplay(w);
}
}
/********************************************************************\
* unsetBusyCursor *
* sets the cursor to the default cursor *
* *
* Args: w - the widget over which to make cursor normal *
* Return: none *
\********************************************************************/
void
unsetBusyCursor( Widget w )
{
if( realized )
{
XUndefineCursor(XtDisplay(w),XtWindow(w));
XmUpdateDisplay(w);
}
}
/********************************************************************\
**************** VERIFYBOX STUFF ***********************************
\********************************************************************/
typedef struct _verifybox {
Boolean done;
Boolean answer;
} VerifyBox;
void verifyBoxCB( Widget mw, XtPointer cd, XtPointer cb );
/********************************************************************\
* verifyBox *
* display a message, and asks the user to press "Ok" or "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent widget *
* title - the title of the window *
* text - the message to display *
* Return: none *
\********************************************************************/
Boolean
verifyBox( Widget parent, char *text )
{
Widget dialog,msgbox;
/* XmString message = XmStringCreateSimple(text); */
XmString message = XmStringCreateLtoR( text, charset );
XmString yes,no;
VerifyBox verifyData;
verifyData.done = False;
verifyData.answer = False;
setBusyCursor( parent );
/* Create the dialog box... XmNdeleteResponse is set to
* XmDESTROY so the dialog's memory is freed when it is closed */
dialog = XtVaCreatePopupShell( "dialog",
xmDialogShellWidgetClass, parent,
XmNdialogStyle, XmDIALOG_APPLICATION_MODAL,
XmNtitle, "",
XmNwidth, 300,
XmNdeleteResponse, XmDESTROY,
NULL );
yes = XmStringCreateSimple(YES_STR);
no = XmStringCreateSimple(NO_STR);
/* Create a messagebox.... has message and "Ok","Cancel" buttons */
msgbox =
XtVaCreateManagedWidget( "dialog",
xmMessageBoxWidgetClass, dialog,
XmNdialogType, XmDIALOG_QUESTION,
XmNdefaultButtonType,XmDIALOG_CANCEL_BUTTON,
XmNmessageString, message,
XmNcancelLabelString,no,
XmNokLabelString, yes,
NULL );
/* Get rid of the "Help" Button!! */
XtUnmanageChild( XmMessageBoxGetChild(msgbox, XmDIALOG_HELP_BUTTON) );
/* We can make verifyData an automatic variable, and pass it by
* reference because this function doesn't return until the
* dialog is destroyed, which means that the callbacks are done */
XtAddCallback( msgbox, XmNokCallback, verifyBoxCB, &verifyData );
XtAddCallback( msgbox, XmNcancelCallback, verifyBoxCB, &verifyData );
XtPopup( dialog, XtGrabNone );
unsetBusyCursor( parent );
/* while the user hasn't pushed "Ok" or "Cancel", simulate XtMainLoop.
* When verifyData.done changes from False, it means the user has
* pressed a button. Don't break loop until XtAppPending() also
* returns False to assure widget destruction. */
while( !(verifyData.done) || XtAppPending(app) )
XtAppProcessEvent( app, XtIMAll );
XmStringFree(message);
XmStringFree(yes);
XmStringFree(no);
return verifyData.answer;
}
/********************************************************************\
* verifyBoxCB *
* *
* Args: mw - the widget that called us *
* cd - verifyData *
* cb - *
* Return: none *
\********************************************************************/
void
verifyBoxCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *)cb;
VerifyBox *verifyData = (VerifyBox *)cd;
switch( cbs->reason )
{
case XmCR_OK:
verifyData->answer = True;
break;
case XmCR_CANCEL:
default:
verifyData->answer = False;
}
verifyData->done = True;
}
/********************************************************************\
*********************************************************************
\********************************************************************/
/********************************************************************\
* errorBox *
* displays an error dialog box *
* *
* Args: w - the parent widget *
* message - the error message to display *
* Return: none *
\********************************************************************/
void
errorBox( Widget parent, char *message )
{
Widget dialog;
if( message != NULL )
{
XmString warning_msg,
dialogname;
setBusyCursor( parent );
/* Create a warning dialog */
dialog = XmCreateWarningDialog( parent, "warning", NULL, 0 );
/* Create the warning XmString */
warning_msg = XmStringCreateLtoR( message, charset );
dialogname = XmStringCreateSimple( WARN_STR );
XtVaSetValues( dialog,
XmNdialogTitle, dialogname,
XmNmessageString, warning_msg,
NULL );
/* Get rid of the "Help" and "Cancel" buttons that would normally
* be in the warning dialog dialog by unmanaging them */
XtUnmanageChild( XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON) );
XtUnmanageChild( XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON) );
/* Register the callback for the "Ok" button */
XtAddCallback( dialog, XmNokCallback, destroyShellCB, dialog );
/* Free up the allocated XmStrings */
XmStringFree( warning_msg );
XmStringFree( dialogname );
XtManageChild( dialog );
unsetBusyCursor( parent );
}
}
/************************* END OF FILE ******************************\
\********************************************************************/

381
src/xtutil.c Normal file
View File

@ -0,0 +1,381 @@
/********************************************************************\
* util.c -- utility functions that are used everywhere else for *
* xacc (X-Accountant) *
* Copyright (C) 1997 Robin D. Clark *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
* Author: Rob Clark *
* Internet: rclark@cs.hmc.edu *
* Address: 609 8th Street *
* Huntington Beach, CA 92648-4632 *
\********************************************************************/
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <Xm/Xm.h>
#include <Xm/Text.h>
#include <Xm/PanedW.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/DialogS.h>
#include <Xm/RowColumn.h>
#include <Xm/MessageB.h>
#include <Xbae/Matrix.h>
#include "config.h"
#include "main.h"
#include "util.h"
#include "xtutil.h"
/** GLOBALS *********************************************************/
extern XtAppContext app;
extern int realized;
/********************************************************************\
* dateCB -- ensures the data the user enters in the date field *
* is in a valid format. *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - the callback struct *
* Return: none *
\********************************************************************/
void
dateCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)cb;
char input;
/* TODO: ??? add support for date field accelerator keys!! */
if( cbs->text->ptr != NULL )
{
input = (cbs->text->ptr)[0];
switch( input )
{
case '/':
/* Make sure that there is at most two '/' */
{
String str = XmTextGetString(mw);
int i,count=0;
for( i=0; str[i] != '\0'; i++ )
if( str[i] == '/' )
count++;
if( count >= 2 )
cbs->doit = False;
}
break;
case 0x0:
/* if delete key (for example) is hit, then input string */
/* will be an empty string. In such a case, allow the input */
cbs->doit = True;
break;
default:
/* only accept the input if it is a number */
cbs->doit = isNum(input);
}
}
}
/********************************************************************\
* amountCB -- ensures the data entered in the amount field is in *
* a valid format. *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - the callback struct *
* Return: none *
\********************************************************************/
void
amountCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)cb;
char input;
if( cbs->text->ptr != NULL )
{
input = (cbs->text->ptr)[0];
switch( input )
{
case '.':
/* Make sure that there is only one '.' */
{
String str = XmTextGetString(mw);
int i,count=0;
for( i=0; str[i] != '\0'; i++ )
if( str[i] == '.' )
count++;
if( count >= 1 )
cbs->doit = False;
}
break;
default:
/* only accept the input if it is a number */
cbs->doit = isNum(input);
}
}
}
/********************************************************************\
* noeditCB *
* makes an Xbae matrix non-editable *
* *
* Args: mw - the widget that called us *
* cd - *
* cb - *
* Return: none *
\********************************************************************/
void
noeditCB( Widget mw, XtPointer cd, XtPointer cb )
{
XbaeMatrixEnterCellCallbackStruct *cbs =
(XbaeMatrixEnterCellCallbackStruct * )cb;
cbs->doit = False;
}
/********************************************************************\
* destroyShellCB *
* a callback to destroy a widget (cd, not w, because we want to *
* destroy a window, not a button!) *
* *
* Args: mw - the widget that called us *
* cd - the widget to destroy *
* cb - *
* Return: none *
\********************************************************************/
void
destroyShellCB( Widget w, XtPointer cd, XtPointer cb )
{
Widget window = (Widget)cd;
XtDestroyWidget(window);
}
/********************************************************************\
* setBusyCursor *
* sets the cursor to the busy watch *
* *
* Args: w - the widget over which to make cursor busy *
* Return: none *
\********************************************************************/
void
setBusyCursor( Widget w )
{
if( realized )
{
static Cursor watch = 0;
if( watch == 0 )
watch = XCreateFontCursor(XtDisplay(w),XC_watch);
XDefineCursor(XtDisplay(w),XtWindow(w),watch);
XmUpdateDisplay(w);
}
}
/********************************************************************\
* unsetBusyCursor *
* sets the cursor to the default cursor *
* *
* Args: w - the widget over which to make cursor normal *
* Return: none *
\********************************************************************/
void
unsetBusyCursor( Widget w )
{
if( realized )
{
XUndefineCursor(XtDisplay(w),XtWindow(w));
XmUpdateDisplay(w);
}
}
/********************************************************************\
**************** VERIFYBOX STUFF ***********************************
\********************************************************************/
typedef struct _verifybox {
Boolean done;
Boolean answer;
} VerifyBox;
void verifyBoxCB( Widget mw, XtPointer cd, XtPointer cb );
/********************************************************************\
* verifyBox *
* display a message, and asks the user to press "Ok" or "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent widget *
* title - the title of the window *
* text - the message to display *
* Return: none *
\********************************************************************/
Boolean
verifyBox( Widget parent, char *text )
{
Widget dialog,msgbox;
/* XmString message = XmStringCreateSimple(text); */
XmString message = XmStringCreateLtoR( text, charset );
XmString yes,no;
VerifyBox verifyData;
verifyData.done = False;
verifyData.answer = False;
setBusyCursor( parent );
/* Create the dialog box... XmNdeleteResponse is set to
* XmDESTROY so the dialog's memory is freed when it is closed */
dialog = XtVaCreatePopupShell( "dialog",
xmDialogShellWidgetClass, parent,
XmNdialogStyle, XmDIALOG_APPLICATION_MODAL,
XmNtitle, "",
XmNwidth, 300,
XmNdeleteResponse, XmDESTROY,
NULL );
yes = XmStringCreateSimple(YES_STR);
no = XmStringCreateSimple(NO_STR);
/* Create a messagebox.... has message and "Ok","Cancel" buttons */
msgbox =
XtVaCreateManagedWidget( "dialog",
xmMessageBoxWidgetClass, dialog,
XmNdialogType, XmDIALOG_QUESTION,
XmNdefaultButtonType,XmDIALOG_CANCEL_BUTTON,
XmNmessageString, message,
XmNcancelLabelString,no,
XmNokLabelString, yes,
NULL );
/* Get rid of the "Help" Button!! */
XtUnmanageChild( XmMessageBoxGetChild(msgbox, XmDIALOG_HELP_BUTTON) );
/* We can make verifyData an automatic variable, and pass it by
* reference because this function doesn't return until the
* dialog is destroyed, which means that the callbacks are done */
XtAddCallback( msgbox, XmNokCallback, verifyBoxCB, &verifyData );
XtAddCallback( msgbox, XmNcancelCallback, verifyBoxCB, &verifyData );
XtPopup( dialog, XtGrabNone );
unsetBusyCursor( parent );
/* while the user hasn't pushed "Ok" or "Cancel", simulate XtMainLoop.
* When verifyData.done changes from False, it means the user has
* pressed a button. Don't break loop until XtAppPending() also
* returns False to assure widget destruction. */
while( !(verifyData.done) || XtAppPending(app) )
XtAppProcessEvent( app, XtIMAll );
XmStringFree(message);
XmStringFree(yes);
XmStringFree(no);
return verifyData.answer;
}
/********************************************************************\
* verifyBoxCB *
* *
* Args: mw - the widget that called us *
* cd - verifyData *
* cb - *
* Return: none *
\********************************************************************/
void
verifyBoxCB( Widget mw, XtPointer cd, XtPointer cb )
{
XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *)cb;
VerifyBox *verifyData = (VerifyBox *)cd;
switch( cbs->reason )
{
case XmCR_OK:
verifyData->answer = True;
break;
case XmCR_CANCEL:
default:
verifyData->answer = False;
}
verifyData->done = True;
}
/********************************************************************\
*********************************************************************
\********************************************************************/
/********************************************************************\
* errorBox *
* displays an error dialog box *
* *
* Args: w - the parent widget *
* message - the error message to display *
* Return: none *
\********************************************************************/
void
errorBox( Widget parent, char *message )
{
Widget dialog;
if( message != NULL )
{
XmString warning_msg,
dialogname;
setBusyCursor( parent );
/* Create a warning dialog */
dialog = XmCreateWarningDialog( parent, "warning", NULL, 0 );
/* Create the warning XmString */
warning_msg = XmStringCreateLtoR( message, charset );
dialogname = XmStringCreateSimple( WARN_STR );
XtVaSetValues( dialog,
XmNdialogTitle, dialogname,
XmNmessageString, warning_msg,
NULL );
/* Get rid of the "Help" and "Cancel" buttons that would normally
* be in the warning dialog dialog by unmanaging them */
XtUnmanageChild( XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON) );
XtUnmanageChild( XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON) );
/* Register the callback for the "Ok" button */
XtAddCallback( dialog, XmNokCallback, destroyShellCB, dialog );
/* Free up the allocated XmStrings */
XmStringFree( warning_msg );
XmStringFree( dialogname );
XtManageChild( dialog );
unsetBusyCursor( parent );
}
}
/************************* END OF FILE ******************************\
\********************************************************************/