home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume4
/
xgen
/
part03
/
help.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-29
|
3KB
|
174 lines
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Core.h>
#include <X11/Text.h>
#include <X11/AsciiText.h>
#include <X11/AsciiTextP.h>
#include "application.h"
extern int max_help_msg_width;
extern int max_help_msg_height;
extern int max_error_msg_width;
extern int max_error_msg_height;
extern XFontStruct *help_msg_font;
extern XFontStruct *error_msg_font;
extern Widget help_msg_widget;
extern Widget error_msg_widget;
extern Widget label_error_widget;
extern Widget label_help_widget;
void
popup_help();
void
button_help( w, closure, call_data)
Widget w;
caddr_t closure;
caddr_t call_data;
{
popup_help( closure );
}
void
help(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
char *help_string;
char *get_hash_help();
help_string = get_hash_help(w);
if( help_string == NULL )
help_string = "Sorry, I can't find any help for this item";
popup_help( help_string);
}
/*These routines will resize the message according to the */
/*string that will be displayed and replace the old string by */
/*the new one and pop the corresponding msgboard to the screen */
void
popup_help(string)
char *string;
{
int width;
int i = 0;
int char_height,
height;
Arg args[15];
XtTextBlock text;
static char *old_string = "";
Widget help_widget;
Widget get_shell_address();
if( string == NULL )
return;
help_widget = get_shell_address("help");
width = XTextWidth(help_msg_font, string, strlen(string));
char_height = help_msg_font->ascent + help_msg_font->descent;
height = (width/max_help_msg_width +2)* char_height;
if (width > max_help_msg_width)
{
width = max_help_msg_width;
XtSetArg(args[i], XtNwidth,
max_help_msg_width);
i++;
XtSetArg(args[i], XtNheight, height+2);
i++;
}
else
{
XtSetArg(args[i], XtNwidth, width+2);
i++;
XtSetArg( args[i], XtNheight, 2*char_height +2);
i++;
}
XtSetValues( help_msg_widget, args, i);
XtSetValues( label_help_widget, args, 1);
text.firstPos = 0;
text.ptr = string;
text.length = strlen(string);
popup(help_widget, "help");
XtTextReplace( help_msg_widget, 0, strlen(old_string), &text);
old_string = string;
}
void
popup_error(string)
char *string;
{
int width;
int i = 0;
int char_height,
height;
Arg args[15];
XtTextBlock text;
static char *old_string = "";
Widget error_widget;
Widget get_shell_address();
if( string == NULL )
return;
error_widget = get_shell_address("error");
width = XTextWidth(error_msg_font, string, strlen(string));
char_height = error_msg_font->ascent + error_msg_font->descent;
height = (width/max_error_msg_width +2)* char_height;
if (width > max_error_msg_width)
{
width = max_error_msg_width;
XtSetArg(args[i], XtNwidth,
max_error_msg_width);
i++;
XtSetArg(args[i], XtNheight, height+2);
i++;
}
else
{
XtSetArg(args[i], XtNwidth, width+2);
i++;
XtSetArg( args[i], XtNheight, 2*char_height +2);
i++;
}
XtSetValues( error_msg_widget, args, i);
XtSetValues( label_error_widget, args, 1);
text.firstPos = 0;
text.ptr = string;
text.length = strlen(string);
popup(error_widget, "error");
XtTextReplace( error_msg_widget, 0, strlen(old_string), &text);
old_string = string;
}