home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- REP_INI.C
- Report Ease initialization and exit functions.
-
- ReportEase Plus
- Sub Systems, Inc.
- ReportEase Plus, Copyright (c) 1993, Sub Systems, Inc. All Rights Reserved.
- 159 Main Street, #8C, Stoneham, MA 02180
- (617) 438-8901.
-
- Software License Agreement (1993)
- ----------------------------------
- This license agreement allows the purchaser the right to modify the
- source code to incorporate in their application.
- The target application must not be distributed as a standalone report writer
- or a mail merge product.
- Sub Systems, Inc. reserves the right to prosecute anybody found to be
- making illegal copies of the executable software or compiling the source
- code for the purpose of selling there after.
-
- ===============================================================================*/
- #include "windows.h"
-
- #if defined (_WIN32)
- #if !defined(WIN32)
- #define WIN32
- #endif
- #endif
- #if !defined(WIN32)
- #include "print.h"
- #endif
-
- #include "stdio.h"
- #include "stdlib.h"
- #include "ctype.h"
- #include "fcntl.h"
- #include "io.h"
- #include "sys\types.h"
- #include "sys\stat.h"
- #include "string.h"
- #include "setjmp.h"
-
- #include "rep.h"
-
- #define PREFIX extern
- #include "rep1.h"
-
- BOOL ReportEaseActive=FALSE; // TRUE when report ease has been called
-
- /*****************************************************************************
- InitFr:
- a. Construct a window class for FORM and create a window.
- b. Initialize pointer and line length arrays.
- c. Read the input file or parse the input buffer.
- d. Initialize cursor, etc.
-
- This function return 0 on a successful execution, otherwise it
- returns an error code.
- *****************************************************************************/
- BOOL InitFr (DWORD WinStyle, int x,int y, int width, int height)
- {
- // create a window class and the main ter edit window
-
- WNDCLASS wc;
- char string[100],ClassName[20];
-
- if (ReportEaseActive) {
- MessageBox(hFrParentWnd,"Report Ease Already Active!",NULL,MB_OK);
- return ERR_DUPLICATE;
- }
- ReportEaseActive=TRUE;
-
- //********** initialization ********************
- InitVariables(); // initialize the global variables
-
- AllocArrayMem(); // allocate memory for line data arrays
-
-
- //***********************************************************************
- if (CurrentPrinter(PrinterName,PrinterDriver,PrinterPort)) {
- if (!InitPrinter()) return ERR_PRINTER; // get current printer info
- }
- else return ERR_PRINTER;
-
- //****************** set screen window or the printer characteristics ***
- if (UseScreen) { // create the window
- if (SessionType=='F') strcpy(ClassName,"FrClass");
- else strcpy(ClassName,"RepClass");
-
- //****** register class ******
- wc.style = CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW|CS_BYTEALIGNCLIENT; // allocate a DC for this class
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hFrInst;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- if (SessionType=='F') wc.hCursor = NULL; // under form editor control
- else wc.hCursor = LoadCursor(NULL,IDC_ARROW); // use default cursor
- wc.hbrBackground = GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- if (SessionType=='F') wc.lpfnWndProc = (void far *)FrWndProc;
- else wc.lpfnWndProc = (void far *)RepWndProc;
- wc.lpszClassName = ClassName;
- RegisterClass(&wc); // class registered
-
- if (FrFileName[0]==0) strcpy(string,"(UNNAMED)");else strcpy(string,FrFileName);
-
- hFrMenu=0;
- if (SessionType=='F') {
- if (FormArg.ShowMenu) hFrMenu=LoadMenu(hFrInst,"FrMenu");
- }
- else hFrMenu=LoadMenu(hFrInst,"RepMenu");
-
- WindowBeingCreated=TRUE; //to avoid certain functions during a window creation
-
- hFrWnd = CreateWindow(ClassName,string,WinStyle,x,y,width,height,hFrParentWnd,hFrMenu,hFrInst,NULL);
-
- if (SessionType=='F') FormArg.hFrWnd=hFrWnd;
-
- ShowWindow(hFrWnd, SW_SHOW);
- SetFocus(hFrWnd);
- ValidateRect(hFrWnd,NULL); // No need to paint right now
- }
- else hFrWnd=hFrParentWnd; // set printer device context
-
- InitDeviceProp(); // initialize device properties
- WindowBeingCreated=FALSE;
-
- //***************** Allocate wrap buffer and read file ***************
-
- lstrcpy(string,FrFileName); // temporarily convert far to near pointer
- if (!FrRead(string)) return ERR_IO;
-
- if (FrShowHorBar || FrShowVerBar) SetScrollBars();
-
- if (SessionType=='F') {
- GetWinDimension(); // recalculate the window dimensions
- PaintFlag=PAINT_WIN;
- FrPaint();
- }
-
- FrModified=FALSE;
-
- return 0; // successful
- }
-
- /******************************************************************************
- InitVariables:
- Initialize the global variables.
- *******************************************************************************/
- void InitVariables()
- {
- int i;
-
- SelItem =-1; // selected screen item
- TotalItems =0; // Total Screen items
- CharHeight =0; // height of a character using the default font
- CurCmd =-1; // Store the id of the current command
- TotalTabRects =0; // number of tab rectangle being displayed
- hDescWnd =NULL; // field and label description window
- hBM =NULL; // Compatible bitmap handle
- FrWidth =0; // Screen form width
- FrHeight =0; // Screen for height
- FrWinOrgX =0; // current horizontal window x co-ordinate in the logical space
- FrWinOrgY =0; // current vertical window x co-ordinate in the logical space
-
- FocusRectDrawn=FALSE; // Turn of the focus rectangle
- IgnoreMouseMove=TRUE; // ignore mouse move until a mouse button is depressed
-
- hFrWnd =NULL; // window handle
- hFrFont =NULL; // initialize the font variables
- FrFont =NULL;
- TotalFonts =0; // not fonts created yet
-
- hMetaFile =0; // initialize the metafile handle
- hMetaDC =0; // initialize the metafile device context
-
- ReportStatus =REP_RESUMED; // can have suspended,resumed,over and abort values
-
- WindowBeingCreated=FALSE; // TRUE when a window is being created
-
- DrawColor =0x00000000; // Color to draw ruler, input area, and divider lines
- BackColor =0x00FFFFFF; // background color
- InputAreaColor=0x007F7F7F; // input area color
- SelectionColor=0x000000FF; // Multiple selection rectangle
- OptRectColor =0x007F7F00; // color of the option rectangles
-
- FrHelpWanted =FALSE; // TRUE when help is requested
- FrModified =FALSE; // file modification flag
- strcpy(FrHelpFile,"REP.HLP");// FORM help file
-
- FontSign=0xBE; // indicates the beginning of the font table
-
- hDevMode=0;
- hFrDC=0; // window device context
- hPrtDC=0; // printer device context
- hFrAccTable=NULL; // accelerator table handle
-
- PaintEnabled=TRUE; // painting enabled
-
- TotalFields=0; // total fields in the form
- TotalBreakFields=0; // total Break Fields in the form
-
- MsgCallback=NULL; // message callback function
-
- printing=FALSE; // TRUE when selectively printing from screen
-
- OurEditProc = (WNDPROC)MakeProcInstance((FARPROC)FrEditSubclass, hFrInst);
- UndoItem=NULL; // item undo data
-
- // define section names *****************************************
-
- strcpy(SectionName[SEC_HDR_REP] ," Report Header ");
- strcpy(SectionName[SEC_HDR_PAGE] ," Page Header ");
- strcpy(SectionName[SEC_HDR_LVL1] ," Sort 1 Header ");
- strcpy(SectionName[SEC_HDR_LVL2] ," Sort 2 Header ");
- strcpy(SectionName[SEC_HDR_LVL3] ," Sort 3 Header ");
- strcpy(SectionName[SEC_HDR_LVL4] ," Sort 4 Header ");
- strcpy(SectionName[SEC_HDR_LVL5] ," Sort 5 Header ");
- strcpy(SectionName[SEC_HDR_LVL6] ," Sort 6 Header ");
- strcpy(SectionName[SEC_HDR_LVL7] ," Sort 7 Header ");
- strcpy(SectionName[SEC_HDR_LVL8] ," Sort 8 Header ");
- strcpy(SectionName[SEC_HDR_LVL9] ," Sort 9 Header ");
- strcpy(SectionName[SEC_DETAIL1] ," Detail 1 Section ");
- strcpy(SectionName[SEC_DETAIL2] ," Detail 2 Section ");
- strcpy(SectionName[SEC_DETAIL3] ," Detail 3 Section ");
- strcpy(SectionName[SEC_DETAIL4] ," Detail 4 Section ");
- strcpy(SectionName[SEC_DETAIL5] ," Detail 5 Section ");
- strcpy(SectionName[SEC_DETAIL6] ," Detail 6 Section ");
- strcpy(SectionName[SEC_DETAIL7] ," Detail 7 Section ");
- strcpy(SectionName[SEC_DETAIL8] ," Detail 8 Section ");
- strcpy(SectionName[SEC_DETAIL9] ," Detail 9 Section ");
- strcpy(SectionName[SEC_FTR_LVL9] ," Sort 9 Footer ");
- strcpy(SectionName[SEC_FTR_LVL8] ," Sort 8 Footer ");
- strcpy(SectionName[SEC_FTR_LVL7] ," Sort 7 Footer ");
- strcpy(SectionName[SEC_FTR_LVL6] ," Sort 6 Footer ");
- strcpy(SectionName[SEC_FTR_LVL5] ," Sort 5 Footer ");
- strcpy(SectionName[SEC_FTR_LVL4] ," Sort 4 Footer ");
- strcpy(SectionName[SEC_FTR_LVL3] ," Sort 3 Footer ");
- strcpy(SectionName[SEC_FTR_LVL2] ," Sort 2 Footer ");
- strcpy(SectionName[SEC_FTR_LVL1] ," Sort 1 Footer ");
- strcpy(SectionName[SEC_FTR_PAGE] ," Page Footer ");
- strcpy(SectionName[SEC_FTR_REP] ," Report Footer ");
-
- // Initialize the section array
- for (i=0;i<MAX_SECTIONS;i++) {
- section[i].InUse=FALSE;
- section[i].flags=0; // see SFLAG_ flags
- section[i].FirstItem=0;
- section[i].ItemCount=0;
- section[i].columns=1; // number of columns across
- section[i].SelExp[0]=END_OF_EXP; // section selection criteria
- section[i].selected=TRUE; // answer of the selection expression
- memset(section[i].reserved,0,sizeof(section[i].reserved));
- }
-
- // define system fields
- strcpy(SysField[SYS_PAGE].name,"PAGE");
- SysField[SYS_PAGE].type=TYPE_NUM;
- SysField[SYS_PAGE].width=4;
-
- strcpy(SysField[SYS_DATE].name,"DATE");
- SysField[SYS_DATE].type=TYPE_DATE;
- SysField[SYS_DATE].width=10;
-
- strcpy(SysField[SYS_TIME].name,"TIME");
- SysField[SYS_TIME].type=TYPE_TEXT;
- SysField[SYS_TIME].width=10;
-
- strcpy(SysField[SYS_REC_COUNT].name,"REC_COUNT");
- SysField[SYS_REC_COUNT].type=TYPE_NUM;
- SysField[SYS_REC_COUNT].width=6;
-
- strcpy(SysField[SYS_PARA_BREAK].name,"PARA_BREAK");
- SysField[SYS_PARA_BREAK].type=TYPE_TEXT;
- SysField[SYS_PARA_BREAK].width=2;
-
- //**** define the print value types
- strcpy(SumName[SUM_NONE] ,"Value");
- strcpy(SumName[SUM_TOTAL] ,"Total");
- strcpy(SumName[SUM_AVERAGE],"Average");
- strcpy(SumName[SUM_COUNT] ,"Count");
- strcpy(SumName[SUM_MAX] ,"Max");
- strcpy(SumName[SUM_MIN] ,"Min");
-
- //**** define the date formats
- strcpy(DateFormat[DT_MMDDYY] ,"MMDDYY");
- strcpy(DateFormat[DT_DDMMYY] ,"DDMMYY");
- strcpy(DateFormat[DT_MMDDYYYY] ,"MMDDYYYY");
- strcpy(DateFormat[DT_MMMDDYYYY] ,"MMMDDYYYY");
-
- //***** define the operator symbols ****
-
- InitOp(OP_COMMA,",",30,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_ELSE,".ELSE.",40,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_THEN,".THEN.",50,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_IF,".IF.",60,TRUE,FALSE,FALSE,"");
-
- InitOp(OP_OR,".OR.",100,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_AND,".AND.",200,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_EQU,"=",300,FALSE,FALSE,FALSE,"");
- InitOp(OP_NOT_EQU,"<>",300,FALSE,FALSE,FALSE,"");
- InitOp(OP_NOT_EQU2,".",300,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_GT,">",400,FALSE,FALSE,FALSE,"");
- InitOp(OP_LT,"<",400,FALSE,FALSE,FALSE,"");
- InitOp(OP_GTE,">=",400,FALSE,FALSE,FALSE,"");
- InitOp(OP_LTE,"<=",400,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_PART,"$",500,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_PLUS,"+",600,FALSE,FALSE,FALSE,"");
- InitOp(OP_MINUS,"-",600,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_MULT,"*",700,FALSE,FALSE,FALSE,"");
- InitOp(OP_DIV,"/",700,FALSE,FALSE,FALSE,"");
-
- InitOp(OP_NOT,".NOT.",800,TRUE,FALSE,FALSE,"");
-
- InitOp(OP_TOT_OF,".TOTAL-OF.",900,TRUE,TRUE,FALSE,"");
- InitOp(OP_AVE_OF,".AVE-OF.",900,TRUE,TRUE,FALSE,"");
- InitOp(OP_MAX_OF,".MAX-OF.",900,TRUE,TRUE,FALSE,"");
- InitOp(OP_MIN_OF,".MIN-OF.",900,TRUE,TRUE,FALSE,"");
- InitOp(OP_COUNT_OF,".COUNT-OF.",900,TRUE,TRUE,FALSE,"");
-
- InitOp(OP_LEN,"LEN",950,TRUE,FALSE,TRUE, "LEN(string)\t-> Length of a String"); // functions
- InitOp(OP_UPPER,"UPPER",950,TRUE,FALSE,TRUE, "UPPER(string)\t-> Convert to UPPER CASE");
- InitOp(OP_LOWER,"LOWER",950,TRUE,FALSE,TRUE, "LOWER(string)\t-> Convert to lower case");
- InitOp(OP_TRIM,"TRIM",950,TRUE,FALSE,TRUE, "TRIM(string)\t-> Trim Beginning and Ending Spaces ");
- InitOp(OP_WORD,"WORD",950,FALSE,FALSE,TRUE, "WORD(string,num)\t-> Extract a Word from the String");
- InitOp(OP_CHAR,"CHAR",950,FALSE,FALSE,TRUE, "CHAR(string,num)\t-> Extract a character from the String");
-
- InitOp(OP_MIN,"MIN",950,FALSE,FALSE,TRUE, "MIN(num1,num2)\t-> Find Smaller of two Numbers");
- InitOp(OP_MAX,"MAX",950,FALSE,FALSE,TRUE, "MAX(num1,num2)\t-> Find Larger of two Numbers");
- InitOp(OP_ROUND,"ROUND",950,FALSE,FALSE,TRUE,"ROUND(num1,num2)\t-> Round Num1 to Num2 Decimal Places");
- InitOp(OP_INT,"INT",950,TRUE,FALSE,TRUE, "INT(num/string/date)\t-> Convert to Integer Number");
- InitOp(OP_ABS,"ABS",950,TRUE,FALSE,TRUE, "ABS(num)\t-> Find Absolute Value");
-
- InitOp(OP_WEEKDAY,"WEEKDAY",950,TRUE,FALSE,TRUE,"WEEKDAY(date)\t-> Day of the week (string)");
- InitOp(OP_DAY,"DAY",950,TRUE,FALSE,TRUE, "DAY(date)\t-> Extract Day (nn) from a Date");
- InitOp(OP_MONTH,"MONTH",950,TRUE,FALSE,TRUE, "MONTH(date)\t-> Extract Month (nn) from a Date");
- InitOp(OP_YEAR,"YEAR",950,TRUE,FALSE,TRUE, "YEAR(date)\t-> Extract Year (nnnn) from a Date");
-
- InitOp(OP_FIRST_CHARS,"FIRST",950,FALSE,FALSE,TRUE,"FIRST(string,num)\t-> Extract First (num) Characters from the String");
- InitOp(OP_LAST_CHARS,"LAST",950,FALSE,FALSE,TRUE,"LAST(string,num)\t-> Extract Last (num) Characters from the String");
- InitOp(OP_TEXT,"TEXT",950,TRUE,FALSE,TRUE, "TEXT(num/date)\t-> Convert to String Format");
-
- InitOp(OP_LPARAN,"(",1000,FALSE,FALSE,FALSE,"");
- InitOp(OP_RPARAN,")",1000,FALSE,FALSE,FALSE,"");
-
-
- //************* initialize the dialog fields ***************************
- for (i=0;i<MAX_DLGS;i++) {
- DlgField[i].InUse=FALSE;
- memset(DlgField[i].reserved,0,sizeof(DlgField[i].reserved));
- }
-
- //************* initialize the field string ***************************
- for (i=0;i<NAME_WIDTH;i++) FieldString[i]=(char)(BYTE)FIELD_CHAR;
- FieldString[i]=0;
-
- //************* initialize the option rectangle fields *****************
- DrawOptRect=FALSE;
- }
-
- /*****************************************************************************
- InitOp:
- Initialize operator symbol, precedence and unary/binary characteristics
- ******************************************************************************/
- InitOp(int OpId,LPSTR sym,int prec,BOOL unry,BOOL FooterOnly,BOOL fct,LPSTR help)
- {
- int len;
-
- strcpy(OpSym[OpId-FIRST_OP],sym); // operator symbol
- OpPrec[OpId-FIRST_OP]=prec; // operator precedence level
- OpUnary[OpId-FIRST_OP]=unry; // is it a unary operator
- OpFooter[OpId-FIRST_OP]=FooterOnly; // valid only for footers
- OpFct[OpId-FIRST_OP]=fct; // is it a function
-
- len=strlen(help);
- if (NULL==(OpHelp[OpId-FIRST_OP]=OurAlloc(len))) return FALSE;
- if (len>0) lstrcpy(OpHelp[OpId-FIRST_OP],(LPSTR)help); // help message for the operator/function
-
- return TRUE;
- }
-
-
- /*****************************************************************************
- InitNewForm:
- Initialize a new report.
- ******************************************************************************/
- InitNewForm()
- {
- int CurItem;
-
- if (SessionType=='R') return TRUE;
-
- FormHdr.FormSign=FORM_SIGN; // initialized the report hdr
- FormHdr.FileFormatId=CUR_FILE_FORMAT; // file format id
- strcpy(FormHdr.name,FrFileName);// default report
- FormHdr.TotalItems=TotalItems;
- FormHdr.FieldCount=TotalFields; // number of fields in the report
- FormHdr.BreakFieldCount=TotalBreakFields;
- FormHdr.FontCount=TotalFonts; // default font
- FormHdr.flags=0;
- FormHdr.RulerType=RULER_INCH; // select inch ruler
- FormHdr.SecBannerHeight=CharHeight; // height of the section banner
-
- strcpy(FormHdr.DataSetName,FormArg.DataSetName); // store the data set name (optional info)
-
- // initialize the header fields
- FormHdr.LeftMargin=(float).25; // margins in inches
- FormHdr.RightMargin=(float).25;
- FormHdr.TopMargin=(float).5;
- FormHdr.BottomMargin=(float).5;
-
- ProcessPrinterData(); // calculate operational variables from the header data
-
- /*********************** Create Default Sections ********************/
- CurItem=0; // create header title section
- TotalItems=1;
- InitItem(&item[CurItem]); // initialize the current item variables
- item[CurItem].type=SECTION;
- item[CurItem].x=(int)(FormHdr.LeftMargin*UNITS_PER_INCH);
- item[CurItem].y=0;
- item[CurItem].width=FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin));
- item[CurItem].height=DEF_SEC_HEIGHT;
- item[CurItem].section=SEC_HDR_PAGE;
- section[SEC_HDR_PAGE].InUse=TRUE; // define the page header
- section[SEC_HDR_PAGE].ScrItem=CurItem; // reference to the item
-
- FrHeight=item[CurItem].y+item[CurItem].height; // current height of the form
-
- CurItem++; // create the group item
- TotalItems++;
- InitItem(&item[CurItem]); // initialize the current item variables
- item[CurItem].type=GROUP;
- item[CurItem].width=2*DEF_RECT_WIDTH;
- item[CurItem].height=2*DEF_RECT_HEIGHT;
- item[CurItem].x=item[0].x+(item[0].width-item[CurItem].width)/2;
- item[CurItem].y=item[0].y+CharHeight+(item[0].height-CharHeight-item[CurItem].height)/2;
- item[CurItem].section=item[0].section; // place it int the first section
-
-
- CurItem++; // create a detail section
- TotalItems++;
- InitItem(&item[CurItem]); // initialize the current item variables
- item[CurItem].type=SECTION;
- item[CurItem].x=(int)(FormHdr.LeftMargin*UNITS_PER_INCH);
- item[CurItem].y=FrHeight;
- item[CurItem].width=FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin));
- item[CurItem].height=DEF_SEC_HEIGHT;
- item[CurItem].section=SEC_DETAIL1;
- section[SEC_DETAIL1].InUse=TRUE; // define the page header
- section[SEC_DETAIL1].ScrItem=CurItem; // reference to the item
-
- FrHeight=item[CurItem].y+item[CurItem].height; // current height of the form
-
- FormHdr.SelExp[0]=END_OF_EXP; // initialize record selection expression
-
- // initialize the reserved space
- memset(FormHdr.reserved,0,sizeof(FormHdr.reserved));
-
- FrModified=FALSE;
-
- return TRUE;
- }
-
- /*****************************************************************************
- ProcessPrinterData:
- Calculate operational variables from the header fields.
- *****************************************************************************/
- ProcessPrinterData()
- {
- float length,width;
- int i,CurSec,columns;
- char string[64];
- HFONT hSysFont;
-
- // store printer and paper information
- strcpy(FormHdr.PrinterName,PrinterName);
- strcpy(FormHdr.PrinterDriver,PrinterDriver);
- FormHdr.Orientation=pDevMode->dmOrientation;
- FormHdr.PaperSize=pDevMode->dmPaperSize;
- FormHdr.PaperLength=pDevMode->dmPaperLength;
- FormHdr.PaperWidth=pDevMode->dmPaperWidth;
- FormHdr.PrintQuality=pDevMode->dmPrintQuality;
-
- strcpy(string,PrinterDriver);
- string[strlen(string)-4]=0; // strip the .drv extension
- if (hPrtDC) DeleteDC(hPrtDC); // delete old device context
- if ((hPrtDC=CreateDC(string,PrinterName,PrinterPort,pDevMode))!=NULL) {
- POINT pt;
- int PrtResX=GetDeviceCaps(hPrtDC,LOGPIXELSX); // number of pixels per inch of X direction
- int PrtResY=GetDeviceCaps(hPrtDC,LOGPIXELSY); // number of pixels per inch of Y direction
-
- Escape(hPrtDC,GETPHYSPAGESIZE,0,NULL,&pt);
- width=(float)pt.x/PrtResX; // actual page size in inches
- length=(float)pt.y/PrtResY;
- if (SessionType=='R' && UseScreen) { // calculate the default printer font height
- CreateOneFont(hPrtDC,0);
-
- hSysFont=GetStockObject(SYSTEM_FONT); // deselect our font
- SelectObject(hPrtDC,hSysFont);
- DeleteObject(FrFont[0].hFont); // delete the printer font
- FrFont[0].hFont=0;
- }
- }
- else AbortFr("Printer Driver Error!",ERR_PRINTER);
-
- FrWidth=(int)(width*UNITS_PER_INCH); // form width in logical units
-
- PrintWidthInches=width=width-FormHdr.LeftMargin-FormHdr.RightMargin;
- PrintHeightInches=length-FormHdr.TopMargin-FormHdr.BottomMargin;
-
- ReportWidth=LineWidth=(int)(width*GetDeviceCaps(hFrDC,LOGPIXELSX));
-
- // Apply the margin to section items
- for (i=0;i<TotalItems;i++) {
- if (item[i].type!=SECTION) continue;
- CurSec=item[i].section;
- columns=section[CurSec].columns;
- item[i].x=(int)(FormHdr.LeftMargin*UNITS_PER_INCH);
- item[i].width=(FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin)))/columns;
- }
-
- return TRUE;
- }
-
-
- /******************************************************************************
- CloseFr:
- Normal closing of FORM routine
- *******************************************************************************/
- BOOL CloseFr()
- {
- int MessageResult,i;
-
- if (SessionType=='F' && FrModified) { // let user save the modifications
- if (IDYES==(MessageResult=MessageBox(hFrWnd,"Do You Wish to Save the Modifications?","File Modified",MB_YESNOCANCEL))) {
- if (!FrSave(FrFileName)) return FALSE;
- }
- else if (MessageResult==IDCANCEL) return FALSE;
- }
-
- WindowBeingCreated=TRUE; // this disables message processing
-
- if (hDevMode) { // release printer data memory
- GlobalUnlock(hDevMode);
- GlobalFree(hDevMode);
- }
-
-
- // deselect objects from the main device context and release it
- SelectObject(hFrDC,GetStockObject(NULL_BRUSH));
- SelectObject(hFrDC,GetStockObject(NULL_PEN));
- SelectObject(hFrDC,GetStockObject(SYSTEM_FONT));
- if (UseScreen) ReleaseDC(hFrWnd,hFrDC); // screen device context
- else DeleteDC(hFrDC); // printer device context
-
- // delete special printer device context used for font selection
- if (hPrtDC) {
- SelectObject(hPrtDC,GetStockObject(SYSTEM_FONT));
- DeleteDC(hPrtDC); // delete the printer device context
- }
-
- // delete other screen objects
- if (UseScreen) {
- // deselect objects from the memory and picture device contexts
- // and delete the device contexts
- SelectObject(hMemDC,hOldBM);
- SelectObject(hMemDC,GetStockObject(SYSTEM_FONT));
- SelectObject(hMemDC,GetStockObject(NULL_PEN));
- SelectObject(hMemDC,GetStockObject(NULL_BRUSH));
- DeleteDC(hMemDC);
-
- DeleteDC(hPictDC);
-
- // delete other objects
- DeleteObject(hBM); // compatible bitmap
-
- DeleteObject(hBackBrush); // background brush
- DeleteObject(hDrawBrush); // foreground drawing brush
- DeleteObject(hInputAreaBrush); // input area drawing brush
-
- DeleteObject(hFrPen); // delete the regular pen
- DeleteObject(hFocusPen); // delete the focus pen
- DeleteObject(hSelectionPen); // delete the multiple selectio pen
- }
-
- //************ delete fonts **********
- for (i=0;i<TotalFonts;i++) { // delete font objects
- if (FrFont[i].InUse) DeleteFrObject(i);// delete font/picture
- }
-
-
- if (SessionType=='F') FormArg.open=FALSE;// mark the window as closed
-
- if (UseScreen) DestroyWindow(hFrWnd);
-
- // Free metafile
- if (hMetaFile) DeleteMetaFile(hMetaFile);
-
- // free process instance
- FreeProcInstance((FARPROC)OurEditProc);
-
- // relase memory used by line arrays
- GlobalUnlock(hItem);
- GlobalFree(hItem);
-
- GlobalUnlock(hFrFont);
- GlobalFree(hFrFont);
-
- GlobalUnlock(hField);
- GlobalFree(hField);
-
- GlobalUnlock(hTempField);
- GlobalFree(hTempField);
-
-
- //************ release memory used by operator help messages ******
- for (i=0;i<MAX_OPS;i++) OurFree(OpHelp[i]);
-
- ReportEaseActive=FALSE;
-
- if (hFrParentWnd) {
- if (MsgCallback!=NULL) MsgCallback(hFrWnd,REP_CLOSE);
- else SendMessage(hFrParentWnd,REP_CLOSE,0,0L); // inform the parent window of closing
-
- SetFocus(hFrParentWnd);
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- AbortFr:
- Handles an abnormal termination of FORM routine.
- *******************************************************************************/
- void AbortFr(LPSTR desc,UINT code)
- {
-
- if (lstrlen(desc)>0) MessageBox(NULL,desc,"Fatal Error",MB_OK);
- ReportEaseActive=FALSE;
-
- if (SessionType=='F') PostQuitMessage(code);
- else ErrorCode=code;
- // return an error code
- #if defined (WIN32)
- longjmp(FrAbort,-1);
- #else
- Throw((LPCATCHBUF) &FrAbort,-1);
- #endif
- }
-
- /******************************************************************************
- AllocArrayMem:
- Allocate fixed global memory of the following types:
- 1. Memory to store the handle to the line text data.
- 2. Memory to store the handle to the line formatting data.
- 3. Memory to store the fonts structure for the current window.
- 4. Memory to store the line length of each line.
- *******************************************************************************/
- AllocArrayMem()
- {
-
- if ( (NULL==(hItem=GlobalAlloc(GMEM_MOVEABLE,(long)(MAX_ITEMS+1)*(long)sizeof(struct StrItem))))
- || (NULL==(item=(struct StrItem huge *)GlobalLock(hItem)))
- || (NULL==(hFrFont=GlobalAlloc(GMEM_MOVEABLE,(long)(MAX_FONTS)*sizeof(struct StrFont))))
- || (NULL==(FrFont=(struct StrFont far *)GlobalLock(hFrFont)))
- || (NULL==(hField=GlobalAlloc(GMEM_MOVEABLE,(long)(MAX_FIELDS+1)*sizeof(struct StrField))))
- || (NULL==(field=(struct StrField huge *)GlobalLock(hField)))
- || (NULL==(hTempField=GlobalAlloc(GMEM_MOVEABLE,(long)(MAX_TEMP_FIELDS+1)*sizeof(struct StrField))))
- || (NULL==(TempField=(struct StrField huge *)GlobalLock(hTempField))) ) {
- AbortFr("Ran Out of Memory (AllocArrayMem)",ERR_NO_MEM);
- }
- return TRUE;
- }
-
- /******************************************************************************
- InitDeviceProp:
- Initialize Device properties such as display context, fonts etc.
- ******************************************************************************/
- void InitDeviceProp()
- {
- int i,result;
-
- //********************* initialize the font table ******************
- for (i=0;i<MAX_FONTS;i++) InitFrObject(i); // initialize the font table
- TotalFonts=0;
-
- hWaitCursor=LoadCursor(NULL,IDC_WAIT); // load hour glass cursor
- hArrowCursor=LoadCursor(NULL,IDC_ARROW); // Regular Arrow cursor
-
- if (!UseScreen) return;
- //************* properties specific to a screen window *************
-
- if (NULL==(hFrDC=GetDC(hFrWnd))) { // allocate a class DC
- AbortFr("Unable to allocate a Display Context.",ERR_DISPLAY);
- }
- ResY=GetDeviceCaps(hFrDC,LOGPIXELSY); // resolution (pixel/logical inch) of the current device
- ResX=GetDeviceCaps(hFrDC,LOGPIXELSX);
-
- SetLogicalUnit(hFrDC); // set the windows logical units to logical LOMETRIC
-
- //************** establish the default font in the font table **********
- TotalFonts=1;
- FrFont[0].InUse=TRUE; // mark as in-use
- FrFont[0].IsPict=FALSE; // not a picture
- FrFont[0].hFont=NULL;
- if (SessionType=='F') result=SelectBestFont(hFrDC,0,FormArg.FontTypeFace,11);
- else result=SelectBestFont(hFrDC,0,"Courier New",11);
- if (!result) { // font creation error
- AbortFr("Error Creating Font(InitDeviceProp)",ERR_DISPLAY);
- }
-
- hFrRegFont=hFrCurFont=FrFont[0].hFont;
- CharHeight=FrFont[0].height; // height of a character using the default font
-
- if (NULL==SelectObject(hFrDC,hFrRegFont)) { // select the newly created font
- AbortFr("Unable to select the font.",ERR_DISPLAY);
- }
-
- if (!GetTextMetrics(hFrDC,&FrTextMet)) { // get text metric for the newly created font
- AbortFr("Unable to get text metric for the font.",ERR_DISPLAY);
- }
-
- if ( NULL==(hMemDC=CreateCompatibleDC(hFrDC)) // to buffer screen
- || NULL==(hPictDC=CreateCompatibleDC(hFrDC)) ) {// to paint pictures
- AbortFr("Unable to create compatible DC",ERR_DISPLAY);
- }
- SetLogicalUnit(hMemDC); // set the windows logical units to logical LOMETRIC
- SetLogicalUnit(hPictDC); // set the windows logical units to logical LOMETRIC
-
- GetWinDimension(); // get window dimensions
-
- SetBkMode(hFrDC,OPAQUE); // enable opaqe printing of text
-
- hBackBrush=CreateSolidBrush(BackColor); // solid brush to clear the background
- hDrawBrush=CreateSolidBrush(DrawColor); // solid brush to reverse the background
- hInputAreaBrush=CreateSolidBrush(InputAreaColor);// solid brush to clear the input area background
-
- if (NULL==(hFrPen=CreatePen(PS_SOLID,1,DrawColor)) // pen to draw ruler, input area, divider lines
- || NULL==(hFocusPen=CreatePen(PS_DOT,1,DrawColor)) // pen to draw the focus rectangle
- || NULL==(hSelectionPen=CreatePen(PS_SOLID,1,SelectionColor)) ){ // pen to draw the selection rectangle
- AbortFr("Unable to create pens.",ERR_DISPLAY);
- }
-
- if (FrShowHorBar) { // display horizontal scroll bar
- ShowScrollBar(hFrWnd,SB_HORZ,TRUE);
- SetScrollRange(hFrWnd,SB_HORZ,HOR_SCROLL_MIN,HOR_SCROLL_MAX,FALSE);
- HorScrollPos=HOR_SCROLL_MIN;
- SetScrollPos(hFrWnd,SB_HORZ,HorScrollPos,TRUE);
- GetWinDimension(); // get window dimensions
- }
-
- if (FrShowVerBar) { // prepare vertical scroll bar
- ShowScrollBar(hFrWnd,SB_VERT,TRUE);
- SetScrollRange(hFrWnd,SB_VERT,VER_SCROLL_MIN,VER_SCROLL_MAX,FALSE);
- GetWinDimension(); // get window dimensions
- }
-
- if (NULL==(hFrAccTable=LoadAccelerators(hFrInst,"FrAccTable"))) { // load the accelerator table
- AbortFr("Unable to load the accelerator table.",ERR_NO_DEVICE);
- }
-
- if (SessionType=='F') {
- //****** Define cursors *********
- hCrossCursor=LoadCursor(NULL,IDC_CROSS); // Cross cursor
- hHorzCursor=LoadCursor(NULL,IDC_SIZEWE); // Horizontal Cursor
- hVertCursor=LoadCursor(NULL,IDC_SIZENS); // Vertical Cursor
- hDiagCursor=LoadCursor(NULL,IDC_SIZENESW); // Forward diagonal curosr
- hDiagBackCursor=LoadCursor(NULL,IDC_SIZENWSE); // Backward diagonal cursor
- }
-
- ValidateRect(hFrWnd,NULL); // No need to paint right now
- }
-
- /******************************************************************************
- SetLogicalUnit:
- Set the logical unit to 1/10 of logical millimeters.
- *******************************************************************************/
- SetLogicalUnit(HDC hDC)
- {
- SetMapMode(hDC,MM_ANISOTROPIC); // use customized units
-
- SetWindowExtEx(hDC,UNITS_PER_INCH,UNITS_PER_INCH,NULL);// logical dimension
- SetViewportExtEx(hDC,ResX,ResY,NULL); // equivalent device dimension
- return TRUE;
- }
-
- /******************************************************************************
- InitPrinter:
- Read the characteristics for the current printer.
- *******************************************************************************/
- InitPrinter()
- {
- int bytes,len;
- HINSTANCE hDriver;
- int (FAR PASCAL *fpDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
-
- if (hDevMode) {
- GlobalUnlock(hDevMode);
- GlobalFree(hDevMode);
- hDevMode=0;
- pDevMode=NULL;
- }
-
- // add .drv extension to the driver name, if necessary
- len=lstrlen(PrinterDriver);
- if (len<=4 || strcmpi(&(PrinterDriver[len-4]),".DRV")!=0) lstrcat(PrinterDriver,".DRV");
-
- #if defined (WIN32)
- // load the printer driver
- if (OpenPrinter(PrinterName,&hDriver,NULL)) {
- if (0==(bytes=DocumentProperties(hFrParentWnd,hDriver,PrinterName,NULL,NULL,0))) {
- AbortFr("Error Initializing the printer(InitPrinter)",ERR_PRINTER);
- }
- if ( (NULL==(hDevMode=GlobalAlloc(GMEM_MOVEABLE,bytes)))
- || (NULL==(pDevMode=(DEVMODE far *)GlobalLock(hDevMode))) ) {
- AbortFr("Ran Out of Memory (InitPrinter)",ERR_PRINTER);
- }
-
- if (!DocumentProperties(hFrParentWnd,hDriver,PrinterName,pDevMode,NULL,DM_COPY)) {
- AbortFr("Error Initializing the printer(InitPrinter a)",ERR_PRINTER);
- }
-
- ClosePrinter(hDriver);
- return TRUE;
- }
- #endif
-
- // load the printer driver
- if (((WORD)(hDriver=LoadLibrary(PrinterDriver)))<32) {
- AbortFr("Invalid Printer Driver",ERR_PRINTER);
- }
-
- fpDeviceMode=(void far *)GetProcAddress(hDriver,"ExtDeviceMode"); // if available, get the address of ExtDeviceMode function in the library
-
- if (fpDeviceMode!=NULL) { // ExtDeviceMode function is supported by the driver
- // get the size of the printer information block
- if ((bytes=(*fpDeviceMode)(hFrParentWnd,hDriver,NULL,(LPSTR)PrinterName,(LPSTR)PrinterPort,NULL,(LPSTR)NULL,0))<=0) {
- AbortFr("Error Initializing the printer(InitPrinter)",ERR_PRINTER);
- }
-
- if ( (NULL==(hDevMode=GlobalAlloc(GMEM_MOVEABLE,bytes)))
- || (NULL==(pDevMode=(DEVMODE far *)GlobalLock(hDevMode))) ) {
- AbortFr("Ran Out of Memory (InitPrinter)",ERR_PRINTER);
- }
-
- if ((*fpDeviceMode)(hFrParentWnd,hDriver,pDevMode,(LPSTR)PrinterName,(LPSTR)PrinterPort,NULL,(LPSTR)NULL,DM_COPY)<0) {
- AbortFr("Error Initializing the printer(InitPrinter(w,2))",ERR_PRINTER);
- }
- }
-
- FreeLibrary(hDriver); // unload the driver from the memory
-
- return TRUE;
- }
-