Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/Engine/
Upload File :
Current File : /usr/home/beeson/MathXpert/Engine/preferences.c

/* Preference storage for MathXpert,  interface-indepedent part.
See registry.c for the Windows part and 
MacPreferences.m for the Mac part.
 

   M. Beeson
   1.18.00  started
   3.24.00   modified
   4.5.00   added PrintGraphsInColor, get_color_printing, set_color_printing.
   4.6.00 added German to default_installdata
   6.15.00  last modified
   6.24.00 added graph paper initialization in DefaultGraphColors
           and GetFactoryGraphColors
   7.15.00 added wcolors.h and used the identifiers there instead of RGB
   7.16.00 added call to FactoryGraphPaper
   7.22.00 added graphpaper in RegSaveValues
   7.27.01 tinkered with messages in readinit
   8.17.04 removed DeleteTextbook
   8.23.04 changed RecognixSystemKey to HelpWithMathSystemKey;
           created reg.h
   8.24.04 changed the way language support works so that under the key "Languages"
           there is a number stored for "French" and for "German"; the number is 1 if 
           that language is supported and 0 if not.   This will have to be changed explicitly
           if more languages are supported.  [in 2007 changed this, see init_languages]         
   8.31.04 changed KEY_READ | KEY_WRITE to KEY_ALL_ACCESS.           
           wrote copy_whichdisk and called it in RegGetMathXpertKey
   9.9.04  removed copy_whichdisk and modified RegSaveValues not to save 
           whichdisk           
   9.12.04 if 0'd out obsolete code that enable MathXpert to run without being installed,
              by setting its own registry entries.
             Set nlanguages = 3 in RegGetValues
   11.9.04 undid the change of 8.31, and made many other changes designed to support 
           running on a network server, or even locally when logged in under a different
           username than the one who installed MathXpert.  So we must not assume that 
           registry data exists under HKEY_CURRENT_USER or that the user has write permission
           on the registry. 
   11.10.04 added calls to WNetGetUniversalName
   10.3.05 if 0'd out code about textbooks at line 815
           Put message boxes back giving better information if registry reading fails.
   1.30.06 removed unused MAXINIT definition, moved this file to interact.dll, changed MEXPORT declarations accordingly          
   4.7.06 changed itoa to sprintf
   4.9.07 changed lines 445 and 449
   4.27.07 modified treatment of LANGUAGES (so new languages only require registry changes)
           changed assertion at line 1482 to use MAXLANGUAGES, not Initfile.nlang.
   8.13.07 modified RegInitialize to not put up a message box if user doesn't have write permission.           
           Removed the first of two parameters from readinit().
           Modifed readinit to call InitializeDefaults if registry reading fails.  
           Put back the code that was if 0'd out on 9.12.04 so InitializeDefaults will be defined.
           Removed set_tocflag.           
   8.14.07 removed all code dealing with LANGUAGES in registry.           
   1.15.08 modified readinit to always initialize the defaults before even trying to read the registry, 
           in case the return value of reading the registry is true even when it didn't work
   4.3.08  Changed InitializeDefaults to not set nlanguages
   4.17.08  RegGetAllValues had an unused parameter, so I deleted it, and modified the calling code accordingly
            Modified RegGetMathXpertKey to set hMathXpertUserKey to NULL if it can't get it and same for hKeyHelpWithMath
            GetMathXpertUserKey was never called, so I deleted it.
            Set hSubKeys to NULL in RegGetMathXpertKey and checked that it is not NULL in RegInitialize before calling
            RegGetAllValues
   5.28.09  Added include version.h            
            Added #ifndef LAB_EDITION
            modified readinit()
   10.2.09  added conditional compilation for default_installdata, and removed superfluous setting of 
            InitFile.whichdisk in readinit().
   1.4.11  modified RegGetValues to first check if a correctly formatted color string is stored under "Background", and fail if not.
            This is intended to prevent overwriting the defaults with garbage from the registry if the user hasn't had sufficient permissions to 
            write the data into the registry.
   1.19.11 Corrected that change.
   1.19.11 Added get and set functions for 'webgrades' and 'email', new fields of initstruct.
   1.20.11  removed registry key for webgrades
   1.23.11 modified set_email and get_email
   8.11.11 modified InitializeDefaults to check whether WEBGRADES is defined and use it to set o->webgrades
   4.25.13 changed default username and organization.
   4.25.13 added code to create the system key if it isn't there already, in GetMathXpertSystemKey
   5.3.13  modified init_languages, now that we no longer have dynamically loaded language dlls.
   5.20.13 removed all code involving textbooks
           decremented EMAIL and NSUBKEYS because TEXTBOOKS (which was 9) is deleted
   6.14.13 modified readinit to set InitFile.whichdisk.
           Removed CreateMathpertSystemKey,  which was no longer used.
   1.21.13 split this file, preferences.c, off from registry.c
   8.11.17  added SPANISH to init_languages
   9.3.17  removed prototypes of unused functions
   12.11.23 added #ifdef SVG
   2.16.24 removed get_whichdisk()
   2.27.24  added DUTCH and CHINESE; modified readinit()
            changed initialize_defaults to call DefaultGraphColors
   3.1.24  changed nlanguages to 7 in default_install_data, but it's probably never used.
   3.2.24  modified init_graphcolors to change axis colors etc. since graph paper is used.
   3.5.24 made read_init call GetFactoryGraphColors.
   6.23.24  if 0'd out things not used in the Engine
   8.8.24  deleted unused variable in init_languages
*/

#define INTERACT_DLL
 
typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef unsigned long       DWORD;
#define RGB(r,g,b)          ((unsigned long)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
 
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "globals.h"   /* DEMOMODE, AUTOTEST */
#include "graphstr.h"
#include "mpdoc.h"
#include "tdefn.h"
#include "cflags.h"
#include "preferences.h"
#include "natlang.h"
#include "lang.h"

typedef unsigned COLORREF;
#include "wcolors.h"
#include "grpaper.h"
#include "version.h"

#define NGRAPHINITCOLORS 8
#define MAXGRAPHS 6
static char *textbooks[1] = { "Beeson"};

static void InitializeDefaults(installdata *p, initstruct *o);
static installdata default_installdata;
static initstruct InitFile;

#define BUFSIZE 1024
#define NSUBKEYS 10


graphcolorstruct DefaultGraphColors =
   { RED24,             // graphcolor
     BLACK24,           // background;
     LIGHTBLUE24,       // fillcolor
     GREEN24,           // axescolor;
     YELLOW24,          // axeslabelcolor;
     YELLOW24,          // titlecolor;
     BLACK24,           // titlebackgroundcolor;
     YELLOW24,          // bordercolor;
     THICK,             // linethickness
     0                  // 0 means don't use graph paper
                        // this will be replaced
   };
   
static void init_languages(void)
/* check which languages are currently supported, and  initialize those languages in InitFile */
{ int i;
  char buffer[512];
  strcpy(buffer,GetMathpertFolder());
  InitFile.languages[0] = 1;  // English is always there
  InitFile.nlanguages = 1;
  for(i=1;i<MAXLANGUAGES;i++)
     { switch(i)
         { case ENGLISH:
           case GERMAN:
           case FRENCH:
           case ITALIAN:
           case DUTCH:
           case CHINESE:
           case SPANISH: 
              InitFile.languages[i] = 1;
              ++InitFile.nlanguages;
              break;
           default:
              InitFile.languages[i] = 0;
         }
     }         
}

#if 0
/*_______________________________________________________*/
int default_buttonsize(int hres, int fontwidth)
/* hres is the horizontal screen resolution in pixels.
fontsize is the tm.tmAveCharWidth of the system font.
Return 1 if the large bitmaps are the default,
0 if the small bitmaps are the default.
*/
{ if(hres <= 800)
     return 0;  /* small bitmaps at low res regardless of font size */
  if(fontwidth < 9)
     return 0;  /* small bitmaps also high res with small fonts */
  return 1;     /* otherwise large bitmaps */
}
#endif

 /*______________________________________________________ */
int  readinit( int webgrades)
/* this is called early in MathXpert's startup sequence.
It should read the registry and load the data from there
into the InitFile structure.  If there's no MathXpert user
key, or no data there, it initializes that too, using the
MathXpert system data key.  If even that doesn't exist
it initializes that too, storing default data that should
have been stored by the registration program.  This
function should never fail.  Even if writing to the
registry fails, it should still initialize InitStruct to
default values and succeed.
   
*/

{ // int flag; 
  init_languages(); 
  InitializeDefaults(&default_installdata,&InitFile);  // Make sure they get initialized, regardless of registry keys and permissions
  InitFile.webgrades = webgrades;
  int i;
  for(i=0;i<MAXGRAPHS;i++)
    {
      GetFactoryGraphColors(i,&InitFile.graphcolors[i],1);
    }
  return 0;
}

 #if 0
/*_________________________________________________________________*/
 int   get_confirmclose(void)
{ return InitFile.confirmclose;
}
/*________________________________________________________________*/
 void  set_confirmclose(int n)
{ InitFile.confirmclose = n;
  //save_preferences(OPTIONS,&InitFile);

}
/*_________________________________________________________________*/
 char *  username(void)
/* return the user name as recorded in InitFile */
{ return InitFile.username;
}
/*_________________________________________________________________*/
 int  network(void)
/* return nonzero if we are running on a network according to InitFile */
{ return strcmp(InitFile.network, "0");
}
/*___________________________________________________________________*/
 int  inqsound(void)
/* return 1 if sound is on,  0 if it's off */
{ return InitFile.sound;
}

 void  sound(int flag)
/* turn sound on, if flag is nonzero, or off, if flag is zero. */
{ InitFile.sound = flag;
  /* If this is not a network installation, store the flag in
     the file mathpert.ini so the choice will carry over to next time.
  */
 // save_preferences(OPTIONS,&InitFile);
}
/*___________________________________________________________________*/
 void  save_colors(COLORREF background, COLORREF formulas, 
                    COLORREF highlight, COLORREF selection, COLORREF reasons)
/* save the current calculation color settings to InitFile and the registry.
*/
{ InitFile.colors.background = background;
  InitFile.colors.formulas = formulas;
  InitFile.colors.highlight = highlight;
  InitFile.colors.selected = selection;
  InitFile.colors.reasons = reasons;
 // save_preferences(CALCULATIONCOLORS,&InitFile);
}

/*___________________________________________________________________*/
 void  save_graphcolors(int graphnumber,
                             unsigned graphcolor,
                             unsigned background,
                             unsigned fillcolor,
                             unsigned axescolor,
                             unsigned axeslabelcolor,
                             unsigned titlecolor,
                             unsigned bordercolor,
                             double linethickness,
                             int graphpaper   /*index of selected graph paper, or 0 for no graph paper */
                            )
/* save the current graph color settings for the specified graph number
   to mathpert.ini and to InitFile. If this is a network installation,
   only save them to InitFile.
*/

{ InitFile.graphcolors[graphnumber].graphcolor = graphcolor;
  InitFile.graphcolors[graphnumber].background = background;
  InitFile.graphcolors[graphnumber].fillcolor = fillcolor;
  InitFile.graphcolors[graphnumber].axescolor = axescolor;
  InitFile.graphcolors[graphnumber].axeslabelcolor = axeslabelcolor;
  InitFile.graphcolors[graphnumber].titlecolor = titlecolor;
  InitFile.graphcolors[graphnumber].bordercolor = bordercolor;
  InitFile.graphcolors[graphnumber].linethickness = linethickness;
  InitFile.graphcolors[graphnumber].graphpaper = graphpaper;
  //save_preferences(GRAPHCOLORS1 + graphnumber,&InitFile);
}
/*_______________________________________________________________________*/
 int  get_magnification(void)
{ return InitFile.magnification;
}
/*_______________________________________________________________________*/
 void  set_magnification(int m)
/* save the given value (m) as InitFile.magnification, but
do not write to mathpert.ini
*/
{ InitFile.magnification = m;
}
/*_______________________________________________________________________*/
 void  save_magnification(int m)
/* save the given value (m) as InitFile.magnification, and
if not a network installation, save it to mathpert.ini as well.
Hence changed type size will take effect in new documents only
after choosing Save Size Setting.
*/
{ InitFile.magnification = m;
  //save_preferences(OPTIONS, &InitFile);
}
/*_______________________________________________________________________*/
 int  get_buttonsize(void)
{ return InitFile.buttonsize;   /* 1 for large bitmaps, 0 for small bitmaps */
}
/*_______________________________________________________________________*/
 void  set_buttonsize(int m)
/* m nonzero means large bitmaps, m == 0 means small bitmaps.
Set the buttonsize field in InitFile and  save to mathpert.ini
*/
{ InitFile.buttonsize = m;
  //save_preferences(OPTIONS,&InitFile);
}
#endif

/*_______________________________________________________________________*/
 void  get_init_colors(COLORREF ans[5],int *pattern)
/* get the background, formula, highlight, selected, and reason colors,
in that order, as stored in InitFile.  This is called to
initialize colors in each new document.  The colors in InitFile are
set from mathpert.ini (or to the defaults) when MathXpert is opened.
They are changed when the user  changes colors.
Thus color changes will persist to additional documents and to the next Mathpert
session of this user, since the data will be recorded in the registry under H_CURRENT_USER.
*/

{ ans[0] = InitFile.colors.background;
  ans[1] = InitFile.colors.formulas;
  ans[2] = InitFile.colors.highlight;
  ans[3] = InitFile.colors.selected;
  ans[4] = InitFile.colors.reasons;
  *pattern = InitFile.colors.pattern;
}
/*_______________________________________________________________________*/
 void  get_init_graphcolors(int graphnumber, 
COLORREF ans[NGRAPHINITCOLORS],double *linethickness, int *graphpaper)
/* get (in ans) the graph colors for the specified graph number as stored in InitFile.
Pass *graphpaper initially as nonzero or zero, nonzero if you want graphpaper.
*/

{
  int want_graphpaper = (*graphpaper) ? 1 : 0;
  *graphpaper = GetFactoryGraphPaper();
  GraphPaper gp = GetGraphPaper(*graphpaper);
   // if you don't want graph paper:
  ans[0] = InitFile.graphcolors[graphnumber].graphcolor;
  ans[1] = InitFile.graphcolors[graphnumber].background;
  ans[2] = InitFile.graphcolors[graphnumber].fillcolor;
  ans[3] = InitFile.graphcolors[graphnumber].axescolor;
  ans[4] = InitFile.graphcolors[graphnumber].axeslabelcolor;
  ans[5] = InitFile.graphcolors[graphnumber].titlecolor;
  ans[6] = InitFile.graphcolors[graphnumber].bordercolor;
  ans[7] = InitFile.graphcolors[graphnumber].titlebackgroundcolor;
  *linethickness = InitFile.graphcolors[graphnumber].linethickness;
  if(! want_graphpaper)
    { *graphpaper = 0;
      return;
    }
  // so if you do want graphpaper:
  ans[1] = gp.background;
  ans[3] = gp.axescolor;
  ans[4] = gp.axeslabelcolor;
  ans[5] = gp.titlecolor;
  ans[7] = gp.titlebackgroundcolor;
}
#if 0
/*_______________________________________________________________________*/
 int  show_operations_menu(void)
{ return InitFile.operations_menu;
}
/*_______________________________________________________________________*/
 void  set_operations_menu(int n)
{ InitFile.operations_menu = n;
}
#endif
/*_________________________________________________________________________*/
 void  GetFactoryGraphColors(int graphnumber, graphcolorstruct *gc, int flag)
/* fill in the default colors for the specified graph */
/* if flag is nonzero, use the default graph paper, otherwise don't use graph paper */
{ *gc = DefaultGraphColors;
   gc->graphpaper= GetFactoryGraphPaper();
  switch(graphnumber % 6)   /* at present MAXGRAPHS is 6 anyway */
     { case 0:
          gc->graphcolor = RED24;
          break;
       case 1:
          gc->graphcolor = MEDGRAY24;
          break;
       case 2:
          gc->graphcolor = BLUE24;
          break;
       case 3:
          gc->graphcolor = GREEN24;
          break;
       case 4:
          gc->graphcolor = CYAN24;
          break;
       case 5:
          gc->graphcolor = MAGENTA24;
          break;
     }
  if(graphnumber > 0)
     gc->titlecolor =  gc->axeslabelcolor = gc->graphcolor;
  gc->linethickness =  THICK;
  if(!flag)
     return;
  gc->graphpaper =  GetFactoryGraphPaper();
  if(gc->graphpaper)
     { GraphPaper G = GetGraphPaper(gc->graphpaper);
       gc->axescolor = G.axescolor;
       gc->background = G.background;
       if(graphnumber == 0)
          { gc->axeslabelcolor = G.axeslabelcolor;
            gc->titlecolor = G.titlecolor;
          }
     }
}
#if 0
/*_______________________________________________*/
 int get_webgrades(void)
{ return InitFile.webgrades;
}
 void set_webgrades(int n)
// we don't keep this item in the registry at all 
{ InitFile.webgrades = n;
}
 void set_email(char *email)
{ strncpy(InitFile.email,email,80);
  // save_preferences(EMAILKEY,&InitFile);
}

 void get_email(char *buffer)
{ strcpy(buffer, InitFile.email);
}
/*_______________________________________________*/
 void set_color_printing(int n)
/*  turn color printing on or off.  Nonzero is on, zero is off. */
/*  does not check if the printer can actually print in color. */
{ InitFile.PrintGraphsInColor = n;
  //save_preferences(OPTIONS, &InitFile);
}
/*_______________________________________________*/
 int get_color_printing(void)
/* return nonzero if user has selected color printing */
/* does not check if the printer can actually print in color. */
{ return InitFile.PrintGraphsInColor;
}
#endif
/*________________________________________________________________________*/

static installdata default_installdata =
{ ENGLISH,                       /* selected_language   */
  7,                             /* nlanguages          */
  { 1,1,1,1,0,1,0,1,0,0,0,1},    /* supported languages get a 1;*/
  /* ENGLISH, FRENCH, GERMAN, SPANISH, CANADIAN, DUTCH, 
     PORTUGESE, ITALIAN, RUSSIAN, SWEDISH, JAPANESE, CHINESE see lang.h */
   7,   /* whichdisk,  so the default is calculus  */
  "Alfred E. Neumann",   /* username            */
  "Help With Math",   /* organization        */
  1,                             /* ntextbooks          */
  textbooks,                     /* array of textbook author names */
  0                              /* index of the default selected_textbook in the
                                    textbooks array */
};

/*__________________________________________________________________*/

static void InitializeDefaults(installdata *p, initstruct *o)
/* fill *o with the default data including that specified by *p.
*/
{  int i;
#ifndef SVG
   int hres,fontwidth;
#endif
   strcpy(o->username,p->username);
   strcpy(o->organization, p->organization);
//   o->nlanguages = p->nlanguages;  This is now set dynamically by init_languages, based on what language dll's are present.
   o->selected_language = p->selected_language;
   for(i=0;i<MAXLANGUAGES;i++)
      o->languages[i] = p->languages[i];
   o->sound = 1;             /* enable sound                   */
   o->operations_menu = 0;   /* don't show the operations menu */
   o->confirmclose = 1;      /* enable confirm-close dialogs?  */
   o->oldhres = 0;           /* previous horizontal resolution */
   o->oldcxChar = 0;         /* previous system font width     */
   o->colors.background = (unsigned long) CALCULATION_BACKGROUND;
   o->colors.formulas =   (unsigned long) BLACK24;
   o->colors.highlight =  (unsigned long) RED24;
   o->colors.selected =   (unsigned long) SELECTION_COLOR;
   o->colors.reasons =    (unsigned long) BLACK24;
   o->colors.pattern =    0;
   for(int k = 0; k < 6; k++)
     o->graphcolors[k] = DefaultGraphColors;
      
#ifdef SVG
   o->magnification = 19;  // magnification is not used in the Engine
#else
   hres = GetRes(&fontwidth);
   o->magnification = default_magnification(hres,fontwidth);
   o->buttonsize = default_buttonsize(hres,fontwidth);
      /* 0 for small buttons, 1 for large buttons */
   o->PrintGraphsInColor = 0;  /* use black-on-white by default */
#endif
#ifdef WEBGRADES
   o->webgrades = 1;
#else
   o->webgrades = 0;    // WebGrades is off by default
#endif
   strcpy(o->email, "");  // email is an empty string until user enters it
}
 


 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists