#ifndef lint
static char *sccsid = "@(#)xcal_help.c	3.6 (Hillside Systems) 1/16/91";
static char *copyright = "@(#)Copyright 1989,1990 Peter Collinson, Hillside Systems";
#endif  /* lint */
/***

* module name:
	xcal_help.c
* function:
	Generate help screens in separate popup windows
* history:
	Written December 1989
	Peter Collinson
	Hillside Systems
* (C) Copyright: 1989 Hillside Systems/Peter Collinson
	
	For full permissions and copyright notice - see xcal.c
***/
#include <stdio.h>
#include <ctype.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Text.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Paned.h>
#include "xcal.h"

static XtCallbackRec callbacks[] = {
   {NULL,NULL},
   {NULL,NULL}
};

void	addversion();

void
DisplayHelpWindow(str)
	String	str;
{
	Widget		shell, form, title;
	Arg		args[10];
	Cardinal	nargs;
	void		DestroyHelp();
	
	shell = XtCreatePopupShell("help", topLevelShellWidgetClass, toplevel, NULL, 0);

	form =  XtCreateManagedWidget("helpPanel", panedWidgetClass, shell, NULL, 0);

	nargs = 0;
	XtSetArg(args[nargs], XtNshowGrip, False); nargs++;
	XtSetArg(args[nargs], XtNdefaultDistance, 2); nargs++;
	title = XtCreateManagedWidget("helpForm", formWidgetClass, form, args, nargs);
	/*
	 *	Exit button
	 *	Take "Quit" from resources
	 */
	callbacks[0].callback = DestroyHelp;
	callbacks[0].closure = (caddr_t)shell;
	nargs = 0;
	XtSetArg(args[nargs], XtNcallback, callbacks); nargs++;
	XtSetArg(args[nargs], XtNfromHoriz, NULL); nargs++;
	XtSetArg(args[nargs], XtNleft, XtChainLeft); nargs++;
	XtSetArg(args[nargs], XtNright, XtChainLeft); nargs++;
	(void) XtCreateManagedWidget("helpQuit", commandWidgetClass, title, args, nargs);
	/*
	 *	Now the text
	 *	which is the remainder of the panel
	 */
	nargs = 0;
	XtSetArg(args[nargs], XtNshowGrip, False); nargs++;
	XtSetArg(args[nargs], XtNstring, str); nargs++;
	XtSetArg(args[nargs], XtNdisplayCaret, False); nargs++;
	(void) XtCreateManagedWidget("helpText", asciiTextWidgetClass, form, args, nargs);

	XtPopup(shell, XtGrabNone);
}

/* ARGSUSED */
void
DestroyHelp(w, closure, call_data)
	Widget	w;
	caddr_t	closure;
	caddr_t call_data;
{
	XtDestroyWidget((Widget)closure);

}

/*
 *	Help scripts
 */
static char stripHelp[] = "\
The date strip consists of a number of lines of text. \n\n\
Line 1:	The Month and the Year of the strip.\n\
	The information may be duplicated in the window\n\
	manager title line. In this case the line may be omitted\n\
	by setting the resource `useWmTitle' to False.\n\n\
Line 2:	The main control buttons for the strip actioned by the\n\
	left mouse button.\n\
	<	Generates last month's strip in a separate window\n\
	Quit	Close this script\n\
	>	Generates next month's strip in a separate window\n\n\
Line 3: The Help button.\n\
	Help can be suppressed by setting `giveHelp' to False.\n\n\
Then -  A line for each day in the month.\n\
	Each line is two areas:\n\
	The left hand side shows the day in the month and the name of\n\
	the day of the week.`Today' may be highlighted specially in\n\
	this region.\n\
	The right hand side is an active button. When pressed it starts\n\
	up an editor for the day. This will create a file for the day\n\
	in the user's Calendar directory. The label on the button will\n\
	be the first few characters of the file, if there are any.\n\
\n\
XCal was written by Peter Collinson\n\
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";

/* ARGSUSED */
void
StripHelp(w, closure, call_data)
	Widget w;
	caddr_t	closure;
	caddr_t call_data;
{
	static int vadded;

	if (vadded == 0)
	{	vadded = 1;
		addversion(stripHelp);
	}
	DisplayHelpWindow(stripHelp);
}
	
static char editHelp[] = "\
This editing window will create or delete a day file for the day shown\n\
in the title. The file is stored in a directory specified by the resource\n\
`directory', this is usually `Calendar' in your home directory.\n\n\
Calendar will usually contain directories, one for each year,\n\
and the day file will be stored in one of these directories. However,\n\
this makes xcal incompatible with xcalendar - so if the resource\n\
xcalendarCompat is True then the use of subdirectories is suppressed.\n\
The large area in the edit window is a normal text input area. Text is\n\
simply be typed into it, the text is saved by hitting the save button\n\
which is set to sensitive when the text is changed.  Saving an empty\n\
buffer will delete the file.  The Quit button will exit. Some more\n\
questions will be asked if leaving will result in losing information.\n\
\n\
XCal was written by Peter Collinson\n\
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";

/* ARGSUSED */
void
EditHelp(w, closure, call_data)
	Widget w;
	caddr_t	closure;
	caddr_t call_data;
{
	static int vadded;

	if (vadded == 0)
	{	vadded = 1;
		addversion(editHelp);
	}

	DisplayHelpWindow(editHelp);
}
	
/*
 *	Add the external version string
 */
static void
addversion(str)
	register char *str;
{
	extern char version[];
	register int vlen;
	register char *ptr;

	if (ptr = index(str, '+'))
	{	vlen = strlen(version);
		bcopy(version, ptr, vlen);
		ptr[vlen] = '\n';
		ptr[vlen+1] = '\0';
	}
}

static char memoHelp[] = "\
The memo window is intended to do two things. First, it allows a\n\
single button click to display today's actions from your diary.\n\
Second, it provides an editable window whose contents can be saved in\n\
a file.  The idea is that this file will contain reminders and other\n\
notes.  The file is usually called `memo' and is stored in a directory\n\
specified by the resource `directory', usually `Calendar' in your home\n\
directory.\n\
\n\
The window is split into two areas. The top half shows the current\n\
diary entry and cannot be altered. The bottom half contains the memo\n\
file text area. Text is simply be typed into it and is stored saved by\n\
hitting the save button. This will go black when the text is changed.\n\
Saving an empty buffer will delete the file.\n\
\n\
The Quit button will exit. Some more questions will be asked if\n\
leaving will result in losing information.\n\
\n\
XCal was written by Peter Collinson\n\
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";

/* ARGSUSED */
void
MemoHelp(w, closure, call_data)
	Widget w;
	caddr_t	closure;
	caddr_t call_data;
{
	static int vadded;

	if (vadded == 0)
	{	vadded = 1;
		addversion(memoHelp);
	}

	DisplayHelpWindow(memoHelp);
}

static char weeklyHelp[] = "\
The weekly strip consists of a number of lines of text. \n\n\
Line 1: The title\n\
Line 2: The Quit button that removes the strip from the screen\n\
Line 3: The Help Button.\n\
	Help can be suppressed by setting `giveHelp' to False.\n\n\
Then -  A line for each day in the week.\n\
	Each line is two areas:\n\
	The left hand side shows the day in the week\n\
	The right hand side is an active button. When pressed it starts\n\
	up an editor for the day. This will create a file for the day\n\
	in the user's Calendar directory. The label on the button will\n\
	be the first few characters of the file, if there are any.\n\
\n\
XCal was written by Peter Collinson\n\
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
	
/* ARGSUSED */
void
WeeklyHelp(w, closure, call_data)
	Widget w;
	caddr_t	closure;
	caddr_t call_data;
{
	static int vadded;

	if (vadded == 0)
	{	vadded = 1;
		addversion(weeklyHelp);
	}

	DisplayHelpWindow(weeklyHelp);
}

