Sindbad~EG File Manager
/* M. Beeson, for MathXpert Windows version */
/* Set those global variables that depend on the document */
/*
6.10.94 original date
12.5.98 last modified
10.7.04 changed assert(0) to return in deactivate().
Added code involving pdoc->problemnumbers
1.18.06 changed handles to pointers etc.
1.19.06 changed activate() and deactivate to use GetActiveDoc
4.19.13 changed GetWindowLong and SetWindowLong to GetWindowLongPtr and SetWindowLongPtr, doubling offsets.
6.24.13 moved activate_by_hwnd to mathpert.c; added call to hidePointSlope, removed Windows header files.
6.27.13 added destroy_document
6.28.13 made init_doc_data set p->initialized to 1.
9.3.17 deleted pdoc->GraphData inside an if, to get rid of a warning message that it always evaluates to true.
1.30.24 added pdata->DocControlData.autosteps = 0; to init_doc_data
1.31.24 commented out get_init_colors in init_doc_data
2.12.24 added set_language in activate()
2.24.24 changed readinit.c to preferences.c
2.26.24 called readinit(0) in init_doc_data
2.28.24 eliminated code about 'magnification' in init_doc_data
2.28.24 uncommented get_init_colors in init_doc_data
3.1.24 changed COLORREF to unsigned int (from int)
5.11.24 made init_doc_data set gensym_counter to 1.
8.3.24 deleted a line involving TBOUND from activate, as I see no reason for it.
10.29.24 made init_doc_data set graphproblemtype correctly
11.20.24 made init_doc_data initialize pdata.totalsteps and pdata.totalautosteps
11.26.24 removed ->originaltopic
12.31.24 removed line that set docControlData.problemtype, since that field is obsolete now.
12.31.24 removed unused variables u and currentline in needsGraphButton
1.4.25 made needsGraphButton return 0 on RELATED_RATES
8.9.25 made init_docdata set pdata->active_parameter=0
*/
#include <stdio.h> /* FILE, mentioned by wfile.h */
#include <assert.h>
#include <stddef.h>
#include "globals.h"
#include "graphstr.h"
#include "mpdoc.h"
#include "heaps.h"
#include "display.h"
#include "probtype.h"
#include "ssolve.h"
#include "activate.h"
#include "induct.h" /* reset_induction */
#include "automode.h" /* set_control_flags */
#include "mathpert.h" /* hwndDoc */
#include "docdata.h" /* allocate_doc_data */
#include "ptype.h" /* problem_type */
#include "preferences.h" /* get_init_colors, get_magnification */
// #include "status.h" /* set_statusline */ /* commented out for windows independence */
#include "userfunc.h" /* increment_inuse, get_definition, nuserfunctions */
#include "tdefn.h" /* GRAPH_TOPIC */
#include "activedoc.h" /* GetActiveDoc */
#include <stdlib.h> // debug
typedef unsigned int COLORREF;
/*____________________________________________________________________*/
void activate( PDOCDATA pdoc)
/* pdoc is a pointer to a DOCDATA structure */
/* Deactivate the current active document, if any.
Extract the values of the document variables from pdoc
and assign them to the corresponding global variables.
Switch the heap manager to the heap of pdoc. */
/* This gets called whenever we create or activate a symbol
document. */
{
PDOCDATA pActiveDoc = GetActiveDoc();
display_control dcontrol;
int i;
if(pdoc == pActiveDoc && pActiveDoc != NULL)
return; /* this is already the active document, so do nothing */
/* But if both are zero, you should still go ahead and activate;
this is needed when preparing a document made by the Graph Button. */
if(pActiveDoc) /* there already was an active document */
{ /* so deactivate it */
deactivate(pActiveDoc); /* store global variables in document data structure */
}
switch_heaps(pdoc->docnumber);
get_display_control(&dcontrol);
/* so separator and precision are not changed */
pdoc->DocDisplayControlData.separator = dcontrol.separator;
pdoc->DocDisplayControlData.precision = dcontrol.precision;
set_display_control(&pdoc->DocDisplayControlData);
activate_polyvalDLL(&(pdoc->DocPolyData));
activate_symbolDLL(&(pdoc->DocControlData));
/* docnumber, heap, and heapsize are not made global */
init_varDLL(&(pdoc->DocVarData));
init_proverDLL(&(pdoc->DocProverData));
set_language(pdoc->language);
// printf("Setting language to %d\n",pdoc->language); // debug
/* saveas is never made global */
/* neither are magnification and the color fields */
SetActiveDoc(pdoc); /* maintain a static global variable correctly */
#ifndef SVG
for(i=0;i<MAXHOMEWORKS;i++)
{ homework * hw = get_homework(pdoc->homework[i]);
if(hw)
hw->currentproblem = pdoc->problemnumbers[i];
}
#endif
if(!GRAPH_TOPIC(pdoc->currenttopic))
{ ; // set_statusline(1537);
}
/* Use the mouse to select an expression you want to change. */
else
{ if(pdoc->graphs[0])
{ for(i=0;i<pdoc->ngraphs;i++)
{ if(pdoc->graphs[i]->crosshairsflag)
{ /* PointSlope tool is selected */
break;
}
}
}
}
}
/*____________________________________________________________________*/
void deactivate( PDOCDATA pdoc)
/* pdoc is a pointer to a DOCDATA structure */
/* Assign the values of the global variables to the corresponding
document-structure internal variables. This is the inverse of
activate(). */
/* This gets called whenever we deactivate a
document, so that the document structure holds the correct
values. */
{ display_control dcontrol;
PDOCDATA pActiveDoc = GetActiveDoc();
if(pActiveDoc == 0)
return; /* document has already been deactivated, see below */
if(pdoc!= pActiveDoc)
return; /* Only deactivate the active document! */
get_display_control(&dcontrol);
pdoc->DocDisplayControlData = dcontrol;
deactivate_polyvalDLL();
#ifndef SVG
for(int i=0;i<MAXHOMEWORKS;i++)
{ homework *hw = get_homework(pdoc->homework[i]);
if(hw)
pdoc->problemnumbers[i] = hw->currentproblem;
}
#endif
/* Not necessary to touch pdoc->vars; var.DLL modifies that data directly */
SetActiveDoc(NULL); /* Don't call deactivate again on this document */
}
/*___________________________________________________________________*/
int init_doc_data(int kind, PDOCDATA pdata)
/* This is done under WM_CREATE for a symbol or graph document.
It may NOT assume the document is active.
'kind' is either GRAPHDOC or SYMBOLDOC.
pdata->currenttopic has already been set when the message that created
the document was processed.
*/
{ int i,err;
COLORREF colors[5];
readinit(0);
for(i=0;i<MAXHOMEWORKS;i++)
pdata->problemnumbers[i] = 0;
pdata->problemtype = problem_type(pdata->currenttopic,&pdata->mainchoice);
pdata->graphproblemtype = pdata->mainchoice;
pdata->problemready = 0;
pdata->kind = kind;
pdata->version = GetVersionNumber();
err = allocate_doc_data(pdata);
if(err)
return 1;
/* problemtype and currenttopic go to symbols.dll via DocControlData: */
pdata->DocControlData.currenttopic = pdata->currenttopic;
pdata->DocControlData.linebreaks = 1;
pdata->DocControlData.showstepflag = 0;
get_display_control(&pdata->DocDisplayControlData);
get_init_colors(colors,&pdata->DocDisplayControlData.backgroundpattern);
/* this gets the colors currently
in the structure InitFile in readinit.c.
*/
pdata->DocDisplayControlData.backgroundcolor = colors[0];
pdata->DocDisplayControlData.textcolor = get_textcolor();
pdata->DocDisplayControlData.highlightcolor = get_highlightcolor();
pdata->DocDisplayControlData.selectioncolor = get_selectioncolor();
pdata->DocDisplayControlData.reasoncolor = get_reasoncolor();
pdata->textweight = 0; /* not boldface */
pdata->DocControlData.linebreaks = (kind != GRAPHDOC);
/* linebreaks ON in symbol documents but off in graph documents */
pdata->progress = NULL;
pdata->nextProgress = 0;
reset_induction(); /* reset static variables in induct.c */
init_model(pdata->currenttopic,pdata->DocControlData.model);
init_polyvalflags(&pdata->DocPolyData);
pdata->DocPolyData.arith = get_arithflag();
pdata->DocControlData.inhibitions = NULL;
pdata->DocVarData.currentline = -1;
pdata->DocVarData.gensym_counter = 1;
pdata->DocVarData.cofi_counter = 1;
pdata->initialized = 1;
pdata->DocControlData.autosteps = 0;
pdata->DocControlData.totalsteps = 0;
pdata->DocControlData.totalautosteps = 0;
pdata->showGraphButton = 1; // will possibly be changed when we have the problem
pdata->DocVarData.activeparameter = -1; // -1 means so it will be less than nparameters even if there are none.
return 0;
}
/*__________________________________________________________*/
void destroy_document_data(PDOCDATA pDocData)
{ int olddoc,newdoc;
#ifndef SVG
// Engine does not support user-defined functions
/* Are there any user-defined functions here? If so decrement their inuse fields. */
term lhs,rhs;
unsigned g;
for(int j=0;j<nuserfunctions();j++)
{ get_definition(j,&lhs,&rhs);
g = FUNCTOR(lhs);
for(int i=0;i<pDocData->ngraphs;i++)
{ if(contains(pDocData->graphs[i]->function,g))
{ decrement_function_inuse(j);
break;
}
}
}
#endif
olddoc = pDocData->docnumber;
newdoc = switch_heaps(olddoc);
/* If we are destroying the last document then the heap
of THIS document is still in use, so newdoc == olddoc */
release_doc_data(pDocData);
if(newdoc != olddoc)
switch_heaps(newdoc); /* Now that we've finished with the old */
}
/*____________________________________________________*/
int needsGraphButton(PDOCDATA pDocData)
/* return 1 if we should show the GraphButton, 0 if not.
For example when solving linear equations, if there are more than
two equations, then don't show the graph button. Also if the
problem has no variables (is completely numerical), don't show the
graph button.
*/
{ term t = pDocData->function;
int nvars = pDocData->DocVarData.nvariables;
if(nvars == 0)
return 0;
if(pDocData->problemtype == LINEAR_EQUATIONS && ARITY(t) > 2)
return 0; // more than two linear equations
if(pDocData->problemtype == LINEARSYSTEM && ARITY(t) > 2)
return 0;
if(pDocData->problemtype == RELATED_RATES)
return 0;
return 1;
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists