
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curses.h>

#include "loantype.def"
#include "macmenu.def"

/*
*************************************************************************

 ##                                      ##   ##                
 ##                                      ### ###                
 ##       ####    ####   #####    #####  #######  #####   ## ###
 ##      ##  ##      ##  ##  ##  ##      ## # ## ##  ##   ####  
 ##      ##  ##   #####  ##  ##   ####   ##   ## ##  ##   ###   
 ##      ##  ##  ##  ##  ##  ##      ##  ##   ##  #####   ##    
 ######   ####    ###### ##  ##  #####   ##   ##     ##   ##    
                                                 #####          

*************************************************************************

 Module:      LOANHELP.C


 Description: This module contains the code that implements LoansMgr's    
              "Help" and "About" functions.            


 Version:     2.5a1 (SuSE Linux 9.0, gcc compiler)

 Author:      Michael A. Campbell

****************************************************************************
*/

/**/

/*
------------------------------------------
 External variables used
------------------------------------------
*/

extern WINDOW *lm_win;  /* Main ncurses window for loansmgr */
extern WINDOW *pu_win;  /* Popup window for help displays   */

/*
------------------------------------------
 Public "About LoansMgr" Information Sets
------------------------------------------
*/

char *about_loansmgr[] = 
  { " General Information ",
    "                 LOANSMGR for Mac OS X, v2.5a1",
    "                           by",
    "                       CampbellWare",
    "                   1986, 1994, 2005, 2007",
    " ",
    "LoansMgr is a powerful but easy to use loan management",
    "program intended for standard compound interest loans.",
    "LoansMgr handles all basic calculations, and will generate",
    "and maintain loan payment schedules. LoansMgr handles",
    "variable payment intervals (in units of weeks and months),",
    "and regularily scheduled additional principal payments.",
    " ",
    "Thanks are due to Philip A. Campbell, for inspiring many",
    "of LoansMgr's advanced features, and to Graeme B. Boyd",
    "for 'artistic inspiration'.",
    " ",
    "" };

char *legal_disclaimer[] = 
  { " Legal  Disclaimer ",  
    "BY USING  LOANSMGR,  YOU ARE  AGREEING  TO BE BOUND BY THE",
    "TERMS PRESENTED BELOW:",
    " ",
    "You  expressly  acknowledge  and  agree  that  use  of the",
    "LoansMgr   software   (hereafter   referred   to  as  'the",
    "Software')  is at your sole  risk.  The  Software  and the",
    "related  documentation  are  provided  AS IS  and  without",
    "warranty of any kind, express or implied,  including,  but",
    "not limited to, the implied warranties of  merchantability",
    "and fitness for a particular purpose.",
    " ",
    "Under  no  circumstances,   including   negligence,  shall",
    "CampbellWare  be  liable  for any  incidental,  special or",
    "consequential   damages   that  result  from  the  use  or",
    "inability  to use the  Software or related  documentation,",
    "even if advised of the possibility of such damages.",
    " ",
    "" };

char *distribution_agreement[] = 
  { " Distribution Agreement ",
    "LoansMgr is provided free of charge under the terms of the",
    "GNU Public Licence v2. Use and enjoy.                     ",
    " ",
    "" };

char *contact_author[] = 
  { " Contacting The Author ",
    "If you wish to contact the author for any reason (bug",
    "reports, suggestions for new features, complaints about",
    "existing features, gratuitous praise :-) ...), please  ",    
    "send an email to:    ",
    " ",
    "webmaster@campbell-tx.net",
    " ",
    "" };

/**/

/*
-----------------------
 Public Menu Help Sets
-----------------------
*/

char *setup_help [] =
  { " Setup Menu Help ",
    "The Setup Menu allows you to control aspects of the",
    "amortization file's setup. Use the 'N' command to",
    "assign the loan a meaningful name, the 'F' command to",
    "assign the name of the amortization file, the 'D'",
    "command to set the date of the first payment, and the",
    "'L' command to set the number of lines per page in the",
    "generated file.",
    " ",
    "" };

char *profile_help [] =
  { " Profile Menu Help ",
    "The Profile Menu allows you to save or restore the",
    "current set of loan parameters. Use the 'F' command to",
    "set the name of the profile file, and then use either",
    "the 'R' command, to read a previously saved profile, or",
    "the 'W' command to write a new profile file with the",
    "current data. The 'V' command will allow you view the",
    "current data either before writing, or after reading.",
    "Finally, the 'E' command will erase the profile.",
    " ",
    "" };

char *schedule_help [] = 
  { " Schedule Menu Help ",
    "The Schedule Menu allows you to generate and view loan",
    "amortization schedules. These schedules have one entry per",
    " payment, listing principal, interest, total principal to",
    "date, and total interest to date. Use the 'L', 'P', 'I'",
    "and 'C' commands to set up the loan parameters, the 'S'",
    "command to set up the starting date for the payments, the",
    "'F' command to set up amortization file details, and then",
    "the 'S' command to compute and write the amortization file.",
    "The resulting file can be viewed with the 'V' command.",
    " ",
    "The impact of variable payment periods can be examined by",
    "changing the time between payments with the 'T' command,",
    "and the impact of additional principle payments can be",
    "explored by specifying the amount and frequency of the same",
    "with the '$' and '#' commands.",
    " ",
    "" };

char *numpayments_help [] =
  { " Num Payments Menu Help ",
    "The Num Payments Menu allows you to determine the number of",
    "payments that will be needed for a loan with the given",
    "parameters. Use the 'L', 'P', 'I' and 'C' commands to set",
    "the loan parameters, and then the 'S' command to compute",
    "the number of payments required.",
    " ",
    "The impact of variable payment periods can be examined by",
    "changing the time between payments with the 'T' command,",
    "and the impact of additional principle payments can be",
    "explored by specifying the amount and frequency of the same",
    "with the '$' and '#' commands.",
    " ",
    "" };

char *interestrate_help [] = 
  { " Interest Rate Menu Help ",
    "The Interest Rate Menu allows you to compute the interest",
    "rate needed for a loan with the supplied parameters. Use",
    "the 'L', 'P', 'N', and 'C' commands to set up the loan",
    "parameters and then use the 'S' command to compute the",
    "required interest rate.",
    " ",
    "" };

char *paymentsize_help [] = 
  { " Payment Size Menu Help ",
    "The Payment Size Menu allows you to determine the size of",
    "payment that will be needed for a loan with the supplied",
    "parameters. Use the 'L', 'N', 'I', and 'C'  commands to",
    "set up the loan parameters, and then the 'S' command to",
    "compute the required payment size.",
    " ",
    "" };

char *loansize_help [] = 
  { " Loan Size Menu Help ",
    "The Loan Size Menu allows you to determine the size of the",
    "loan that will result from the supplied parameters. Use the",
    " 'P', 'N', 'I', and 'C' commands to set up the loan",
    "parameters, and then the 'S' command to compute the ",
    "resulting loan size.",
    " ",
    "" };

char *main_help[] =
  { " Main Menu Help ",
    "Use the Main Menu to select one of LoanMgr's functions.",
    "o The 'L' command allows you to determine the size of loan",
    "  that results from the parameters you enter.",
    "o The 'P' command allows you to compute the payment size",
    "  that results from the parameters you enter.",
    "o The 'N' command allows you to determine the number",
    "  of payments required by the parameters you enter.",
    "o The 'S' command allows you to generate, view, and save",
    "  loan payment schedules, with equity and interest totals.",
    "o The 'F' command allows you to save your loan data to a",
    "  loan profile file, or restore previously saved data.",
    " ",
    "" }; 

/**/

/*
-------------------------
 External Functions Used
-------------------------
*/

#include "loanutil.ext"

/**/

/*
-----------------------
 Public Help Functions
-----------------------
*/

void show_help ( help_lines, sx, sy, popup_fg, popup_bg, sys_fg, sys_bg, menu )

/***************************************************************************
 *                                                                         *
 * This function creates a help Window, and displays the help in the       *
 * supplied lines. It then waits until the user is ready to carry on,      *
 * and restores the previous menu.                                         *
 *                                                                         *
 ***************************************************************************/

char *help_lines[];      /* Pointer to the help lines                      */
unsigned char sx, sy;    /* The x and y maximums for the system monitor    */
int  sys_fg, sys_bg;     /* The fg and bg colors to use in title, footer   */
int  popup_fg, popup_bg; /* The fg and bg colors to use for text           */
MENU_ID menu;            /* The menu to restore when done                  */

{
   int  lines = 0;  /* The line count                                      */
   int  eat_it;     /* don't care int for absorbing one user keystroke     */
   int  i;          /* Loop counter                                        */

   /* First, figure out how large the window should be, by counting all    */
   /* the lines. Since 20 lines is the max we can display, stop at 20, if  */
   /* not before. We skip the first line, since it is the title.           */

   while ( lines < 20 )
      if ( help_lines[lines++][0] == '\0' )
         break;
   
   /* Create an appropriately sized window using the supplied popup colors. */
   /* One extra line is added to allow a blank line after the title and     */
   /* before the text.                                                      */

   create_popup_window ( sx, sy, W_CENTER, W_CENTER, 64, lines+1, popup_fg, popup_bg );

   for ( i = 1; i < lines-1; i++ )
      mvwprintw ( pu_win, i+1, 2, "%s", help_lines[i] );

   /* Output the title and footer lines                                     */

   adorn_popup_window ( 64, lines+1, popup_fg, popup_bg, help_lines[0],
                        " << Press any key to continue >> " );

   /* Wait for the user to indicate that he/she is ready to move on, and    */
   /* then destroy the window, and restore the main menu.                   */

   eat_it = getch ();

   destroy_popup_window ( sx, sy, menu );

} /* show_help */

/**/

void no_help ( help_lines, sx, sy, popup_fg, popup_bg, sys_fg, sys_bg, menu )

/***************************************************************************
 *                                                                         *
 * This function provides no help at all! This function implements the     *
 * Graeme B. Boyd inspired "tough noogies" help message. This "no help"    *
 * function is invoked only if the user enters the correct hidden command  *
 * to toggle the help level from "Normal" to "Expert".                     *
 *                                                                         *
 * This help command has the same argument list as the real help command,  *
 * as both are the target of a help function pointer in the main LoansMgr  *
 * module.                                                                 *
 ***************************************************************************/

char *help_lines[];      /* Pointer to the help lines                      */
unsigned char sx, sy;    /* The x and y maximums for the system monitor    */
int  sys_fg, sys_bg;     /* The fg and bg colors to use in title, footer   */
int  popup_fg, popup_bg; /* The fg and bg colors to use for text           */
MENU_ID menu;            /* The menu to restore when done                  */

{
   /* First of all, stop the compiler from whining about unused parms by   */
   /* performing a test that will always fail.                             */

   if ( menu == NIL_MENU_ID )
      show_help ( help_lines, sx, sy, popup_fg, popup_bg, sys_fg, sys_bg, menu );

   /* Now, on with the show                                                */

   put_status_string ( "Tough noogies, twit face!" );

} /* no_help */

