home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- REP1.C
- Report Ease - Text Editing 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 "dos.h"
- #include "fcntl.h"
- #include "io.h"
- #include "signal.h"
- #include "string.h"
- #include "malloc.h"
- #include "memory.h"
- #include "sys\types.h"
- #include "sys\stat.h"
- #include "setjmp.h"
-
- #include "rep.h"
-
- #define PREFIX extern
- #include "rep1.h"
-
- /******************************************************************************
- InsertLabelPartI()
- This routine initiates label creation. It defines a cursor rectangle
- for the new label. When the user presses a mouse button, the
- InsertLabelPartII function is used to create at the label the current
- cursor postion.
- *******************************************************************************/
- InsertLabelPartI()
- {
- int LabelHeight,LabelWidth;
-
- if (CurCmd!=-1) return FALSE; // previous command not completed yet
-
- if (TotalItems>=MAX_ITEMS) { // check for item table space
- MessageBox(hFrWnd,"Item Table Full!",NULL,MB_OK);
- return TRUE;
- }
-
- // deselect currently selected item
- if (SelItem>=0) DeselectItem();// deselect the current item
-
- // get label height and width
- LabelHeight=CharHeight;
- LabelWidth=GetLabelLen("Label",DEFAULT_CFMT)+2*DESC_MARGIN;
-
- // define the cursor rectangle
- CursRect.left=FrWinOrgX+(FrWinWidth-LabelWidth)/2;
- CursRect.right=CursRect.left+LabelWidth;
- if (CursRect.right>FrWidth) {
- CursRect.right=FrWidth;
- CursRect.left=CursRect.right-LabelWidth;
- }
- if (CursRect.left<FrWinOrgX) CursRect.left=FrWinOrgX;
- if (CursRect.left>=CursRect.right) return FALSE;
-
- CursRect.top=FrWinOrgY+(FrWinHeight-LabelHeight)/2;
- CursRect.bottom=CursRect.top+LabelHeight;
- if (CursRect.bottom>FrHeight) {
- CursRect.bottom=FrHeight;
- CursRect.top=CursRect.bottom-LabelHeight;
- }
- if (CursRect.top<FrWinOrgY) CursRect.top=FrWinOrgY;
- if (CursRect.top>=CursRect.bottom) return FALSE;
-
- // Draw the focus rectangle
- FrDrawFocusRect(hFrDC,&CursRect);
- FrSetCursor(CursRect.left+(CursRect.right-CursRect.left)/2,CursRect.top+(CursRect.bottom-CursRect.top)/2);
-
- // set the flags
- CurCmd=ID_INSERT_LABEL; // current unfinished command
- IgnoreMouseMove=FALSE; // monitor mouse movements now
- SelItem=-1; // no item selected yet
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertLabelPartII()
- This routine finishes the label creation process started by the
- InsertLabelPartI function. This function is called after the user
- positions the cursor rectangle for the new label.
- *******************************************************************************/
- InsertLabelPartII()
- {
- int CurItem,CurSec;
- struct StrItem NewItem;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- CurItem=FrFindItemSlot(CurSec); // slot where the item will be inserted
-
- // initialize the NewItem
- InitItem(&NewItem); // initialize
- NewItem.type=LABEL; // screen item type: LABEL,FIELD,SECTION,LINE
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.width=CursRect.right-CursRect.left; // width of the object
- NewItem.height=CursRect.bottom-CursRect.top;// height of the object
- NewItem.flags=OFLAG_HCENTER|OFLAG_VCENTER; // Attributes, see OFLAG_ constants
- NewItem.section=CurSec; // Current section
- lstrcpy(NewItem.label,"Label");// label text when type is LABEL
-
- // insert the new item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
-
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- SelItem=CurItem;
- PaintFlag=PAINT_WIN; // to reset the option ribbon highlighting
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertLinePartI()
- This routine initiates a line creation. It defines a cursor rectangle
- for the new line. When the user presses a mouse button, the
- InsertLinePartII function is used to create the line at the current
- cursor postion.
- *******************************************************************************/
- InsertLinePartI()
- {
-
- if (CurCmd!=-1) return FALSE; // previous command not completed yet
-
- if (TotalItems>=MAX_ITEMS) { // check for item table space
- MessageBox(hFrWnd,"Item Table Full!",NULL,MB_OK);
- return TRUE;
- }
-
- // deselect currently selected item
- if (SelItem>=0) DeselectItem();// deselect the current item
-
- // define the cursor rectangle
- CursRect.left=FrWinOrgX+(FrWinWidth-2*DEF_RECT_WIDTH)/2;
- CursRect.right=CursRect.left+2*DEF_RECT_WIDTH;
- if (CursRect.right>FrWidth) {
- CursRect.right=FrWidth;
- CursRect.left=CursRect.right-2*DEF_RECT_WIDTH;
- }
- if (CursRect.left<FrWinOrgX) CursRect.left=FrWinOrgX;
- if (CursRect.left>=CursRect.right) return FALSE;
-
- CursRect.top=FrWinOrgY+(FrWinHeight-DEF_RECT_HEIGHT)/2;
- CursRect.bottom=CursRect.top+DEF_RECT_HEIGHT;
- if (CursRect.bottom>FrHeight) {
- CursRect.bottom=FrHeight;
- CursRect.top=CursRect.bottom-DEF_RECT_HEIGHT;
- }
- if (CursRect.top<FrWinOrgY) CursRect.top=FrWinOrgY;
- if (CursRect.top>=CursRect.bottom) return FALSE;
-
- // Draw the focus rectangle
- FrDrawFocusRect(hFrDC,&CursRect);
- FrSetCursor(CursRect.left+(CursRect.right-CursRect.left)/2,CursRect.top+(CursRect.bottom-CursRect.top)/2);
-
- // set the flags
- CurCmd=ID_INSERT_LINE; // current unfinished command
- IgnoreMouseMove=FALSE; // monitor mouse movements now
- SelItem=-1; // no item selected yet
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertLinePartII()
- This routine finishes the line creation process started by the
- InsertLinePartI function. This function is called after the user
- positions the cursor rectangle for the new line.
- *******************************************************************************/
- InsertLinePartII()
- {
- int CurItem,CurSec;
- struct StrItem NewItem;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- CurItem=FrFindItemSlot(CurSec); // slot where the item will be inserted
-
- // initialize the NewItem
- InitItem(&NewItem); // initialize
- NewItem.type=LINE; // screen item type: LABEL,FIELD,SECTION,LINE
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.width=CursRect.right-CursRect.left; // width of the object
- NewItem.height=CursRect.bottom-CursRect.top;// height of the object
- NewItem.section=CurSec; // Current section
-
- // insert the new item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
-
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- SelItem=CurItem;
- PaintFlag=PAINT_WIN; // to reset the option ribbon highlighting
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertPicturePartI()
- This routine initiates a picture insertion. It gets the picture from
- the clipboard or from the disk file. It then defines the cursor rectangle
- for the new picture. When the user presses a mouse button, the
- InsertPicturePartII function is used to insert the picture at the current
- cursor postion.
- *******************************************************************************/
- InsertPicturePartI(int source)
- {
- int PictWidth,PictHeight;
-
- if (CurCmd!=-1) return FALSE; // previous command not completed yet
-
- if (TotalItems>=MAX_ITEMS) { // check for item table space
- MessageBox(hFrWnd,"Item Table Full!",NULL,MB_OK);
- return TRUE;
- }
-
- // deselect currently selected item
- if (SelItem>=0) DeselectItem();// deselect the current item
-
- // get the picture
- if (source==ID_PICT_FROM_FILE) {
- if (!PictureFromFile()) return TRUE;
- }
- else if (!PictureFromClipboard()) return TRUE;
-
- // define the cursor rectangle
- PictHeight=FrFont[NewPict].height;
- PictWidth=FrFont[NewPict].CharWidth[0];
-
- CursRect.left=FrWinOrgX+(FrWinWidth-PictWidth)/2;
- CursRect.right=CursRect.left+PictWidth;
- if (CursRect.right>FrWidth) {
- CursRect.right=FrWidth;
- CursRect.left=CursRect.right-PictWidth;
- }
- if (CursRect.left<FrWinOrgX) CursRect.left=FrWinOrgX;
- if (CursRect.left>=CursRect.right) return FALSE;
-
- CursRect.top=FrWinOrgY+(FrWinHeight-PictHeight)/2;
- CursRect.bottom=CursRect.top+PictHeight;
- if (CursRect.bottom>FrHeight) {
- CursRect.bottom=FrHeight;
- CursRect.top=CursRect.bottom-PictHeight;
- }
-
- if (CursRect.top<FrWinOrgY) CursRect.top=FrWinOrgY;
- if (CursRect.top>=CursRect.bottom) return FALSE;
-
- // Draw the focus rectangle
- FrDrawFocusRect(hFrDC,&CursRect);
- FrSetCursor(CursRect.left+(CursRect.right-CursRect.left)/2,CursRect.top+(CursRect.bottom-CursRect.top)/2);
-
- // set the flags
- CurCmd=source; // current unfinished command
- IgnoreMouseMove=FALSE; // monitor mouse movements now
- SelItem=-1; // no item selected yet
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertPicturePartII()
- This routine finishes the picture creation process started by the
- InsertPicturePartI function. This function is called after the user
- positions the cursor rectangle for the new picture.
- *******************************************************************************/
- InsertPicturePartII()
- {
- int CurItem,CurSec;
- struct StrItem NewItem;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- CurItem=FrFindItemSlot(CurSec); // slot where the item will be inserted
-
- // initialize the NewItem
- InitItem(&NewItem); // initialize
- NewItem.type=PICT; // screen item type: LABEL,FIELD,SECTION,LINE
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.width=CursRect.right-CursRect.left; // width of the object
- NewItem.height=CursRect.bottom-CursRect.top;// height of the object
- NewItem.section=CurSec; // Current section
- NewItem.font=NewPict; // index into the font/picture table
-
- // insert the new item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
-
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- SelItem=CurItem;
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertFieldPartI:
- This routine initiates a field insertion. It gets the field name from
- the field creation functions. It then defines the cursor rectangle
- for the new field. When the user presses a mouse button, the
- InsertFieldPartII function is used to insert the field at the current
- cursor postion.
- *******************************************************************************/
- InsertFieldPartI(int type)
- {
- int FieldWidth,FieldHeight;
- BOOL result;
- char label[LINE_WIDTH+1];
- MSG msg;
-
- if (CurCmd!=-1) return FALSE; // previous command not completed yet
-
- if (TotalItems>=MAX_ITEMS) { // check for item table space
- MessageBox(hFrWnd,"Item Table Full!",NULL,MB_OK);
- return TRUE;
- }
-
- // deselect currently selected item
- if (SelItem>=0) DeselectItem();// deselect the current item
-
- // get the field name in the field array
- switch (type) {
- case ID_INSERT_DATA:
- result=InsertDataField();break;
- case ID_INSERT_CALC:
- result=InsertCalcField();break;
- case ID_INSERT_SYS:
- result=InsertSysField();break;
- case ID_INSERT_DLG:
- result=InsertDlgField();break;
- }
- // discard any mouse messages left from the above call
- while (PeekMessage(&msg,hFrWnd,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE|PM_NOYIELD));;
- if (!result) { // user cancelled the operation
- PaintFlag=PAINT_WIN; // to reset the option ribbon highlighting
- FrPaint();
- return FALSE;
- }
-
- // find default field width/height
- CreateFieldLabel(NewField,label,0,DEFAULT_CFMT);
- FieldWidth=GetLabelLen(label,DEFAULT_CFMT)+2*DESC_MARGIN;
- FieldHeight=DEF_RECT_HEIGHT;
- if (field[NewField].type==TYPE_PICT) FieldHeight=FieldWidth;
-
- // define the cursor rectangle
- CursRect.left=FrWinOrgX+(FrWinWidth-FieldWidth)/2;
- CursRect.right=CursRect.left+FieldWidth;
- if (CursRect.right>FrWidth) {
- CursRect.right=FrWidth;
- CursRect.left=CursRect.right-FieldWidth;
- }
- if (CursRect.left<FrWinOrgX) CursRect.left=FrWinOrgX;
- if (CursRect.left>=CursRect.right) return FALSE;
-
- CursRect.top=FrWinOrgY+(FrWinHeight-FieldHeight)/2;
- CursRect.bottom=CursRect.top+FieldHeight;
- if (CursRect.bottom>FrHeight) {
- CursRect.bottom=FrHeight;
- CursRect.top=CursRect.bottom-FieldHeight;
- }
-
- if (CursRect.top<FrWinOrgY) CursRect.top=FrWinOrgY;
- if (CursRect.top>=CursRect.bottom) return FALSE;
-
- // Draw the focus rectangle
- FrDrawFocusRect(hFrDC,&CursRect);
- FrSetCursor(CursRect.left+(CursRect.right-CursRect.left)/2,CursRect.top+(CursRect.bottom-CursRect.top)/2);
-
- // set the flags
- CurCmd=type; // current unfinished command
- IgnoreMouseMove=FALSE; // monitor mouse movements now
- SelItem=-1; // no item selected yet
-
- return TRUE;
- }
-
- /******************************************************************************
- InsertFieldPartII()
- This routine finishes the field creation process started by the
- InsertFieldPartI function. This function is called after the user
- positions the cursor rectangle for the new field.
- *******************************************************************************/
- InsertFieldPartII()
- {
- int CurItem,CurSec;
- struct StrItem NewItem;
- struct StrField huge *pField;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- CurItem=FrFindItemSlot(CurSec); // slot where the item will be inserted
-
- // initialize the NewItem
- InitItem(&NewItem); // initialize
- NewItem.type=FIELD; // screen item type: LABEL,FIELD,SECTION,LINE
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.width=CursRect.right-CursRect.left; // width of the object
- NewItem.height=CursRect.bottom-CursRect.top;// height of the object
- NewItem.section=CurSec; // Current section
- NewItem.field=NewField; // index into the field table
- CreateFieldLabel(NewField,NewItem.label,NewItem.width,NewItem.font); // create field label
-
- pField=&field[NewField];
- if (pField->type==TYPE_NUM || pField->type==TYPE_DBL) {
- NewItem.flags=NewItem.flags&(~((UINT)OFLAG_HLEFT|OFLAG_HCENTER)); // reset flags
- NewItem.flags=NewItem.flags|OFLAG_HRIGHT;
- if (CurSec>=SEC_FTR_LVL9 && pField->source!=SRC_SYS) pField->SumType=SUM_TOTAL;
- }
- else if (pField->type==TYPE_PICT) {
- NewItem.OutlineSelect=OUTLINE_LEFT|OUTLINE_RIGHT|OUTLINE_TOP|OUTLINE_BOT;
- }
-
- // insert the new item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
-
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- SelItem=CurItem;
- PaintFlag=PAINT_WIN; // to reset the option ribbon highlighting
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- UpdateLabelText:
- This routine is called when the user edits the label text. This
- routine updates the current label text from the description window.
- *******************************************************************************/
- UpdateLabelText()
- {
- char string[LINE_WIDTH+1];
-
-
- if (SelItem<0 || !hDescWnd) return TRUE; // not applicable
- if (item[SelItem].type!=LABEL) return TRUE;
-
- GetWindowText(hDescWnd,string,LINE_WIDTH);
- string[LINE_WIDTH]=0;
-
- if (lstrcmp(string,item[SelItem].label)!=0) { // text changed
- lstrcpy(item[SelItem].label,string);
-
- UpdateLabelSize(SelItem);
-
- // clear the item background and redraw the item
- FrEraseFocusRect(hFrDC,&CursRect);
-
- FrPaint();
- FrModified=TRUE;
- }
- return TRUE;
- }
-
- /******************************************************************************
- UpdateLabelSize:
- This routine updates the label rectangle size for the current label string
- and font index. The size is not changed for an empty rectangle or rectangle
- whose size was changed by the user by using item size function.
- *******************************************************************************/
- UpdateLabelSize(int CurItem)
- {
- int font;
-
- if (item[CurItem].type!=LABEL) return TRUE;
- if (lstrlen(item[CurItem].label)==0) return TRUE; // do size the blank label
- if (item[CurItem].sized) return TRUE; // do not change the manually sized item
-
- font=item[CurItem].font;
- item[CurItem].width=GetLabelLen(item[CurItem].label,font)+2*DESC_MARGIN;
- item[CurItem].height=FrFont[font].height;
-
- return TRUE;
- }
-
- /******************************************************************************
- MoveItem()
- This routine is called when a mouse button is release as a screen item
- is being moved. When a group item is being relocated, this routine calls
- the MoveEachItem routine to move each item of the group.
- *******************************************************************************/
- MoveItem()
- {
- int i,DeltaX,DeltaY;
-
- if (SelItem<0) return FALSE;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
-
- if (item[SelItem].type!=GROUP) FrAdjustCursorRect(); // adjust the cursor rectangle position
-
- // calculate the amount of location
- DeltaX=CursRect.left-item[SelItem].x;
- DeltaY=CursRect.top-item[SelItem].y;
-
- // check if the item location has changed
- if ( (DeltaX==0 || abs(DeltaX)<(UNITS_PER_INCH/ResX))
- && (DeltaY==0 || abs(DeltaY)<(UNITS_PER_INCH/ResY)) ){
- PaintFlag=PAINT_ITEMS; // do not refresh entire window
- goto END;
- }
- else DiscardUndo(); // discard previous undo
-
- // process the group item
- if (item[SelItem].type==GROUP) {
- // flag the items within this group
- MarkGroupItems();
-
- // move the group item
- MoveEachItem(SelItem,DeltaX,DeltaY);
-
- // move each item within the group
- while (TRUE) {
- // find an item in the group
- for(i=0;i<TotalItems;i++) if (item[i].InGroup) break;
- if (i==TotalItems) break; // all items processed
- item[i].InGroup=FALSE; // reset flag for this item
- MoveEachItem(i,DeltaX,DeltaY);
- }
-
- // locate the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- else AbortFr("Group Item Missing(MoveItem)",ERR_OTHER);
- }
- else { // process the non group item
- SelItem=MoveEachItem(SelItem,DeltaX,DeltaY);
- }
-
- FrModified=TRUE;
-
- END:
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
-
- FrPaint(); // repaint the screen
-
- return TRUE;
- }
-
- /******************************************************************************
- MoveEachItem()
- This routine is called by the MoveItem routine to move one item of
- the group item. This routine returns the new item index.
- *******************************************************************************/
- MoveEachItem(int OrigItem,int DeltaX,int DeltaY)
- {
- int CurItem,CurSec,i;
- struct StrItem NewItem;
- struct StrField huge *pField;
-
- if (DeltaX==0 && DeltaY==0) return OrigItem; // no need to move
-
- // Initialize the NewItem
- HugeMove(&item[OrigItem],&NewItem,sizeof(struct StrItem));
- NewItem.x+=DeltaX; // X position of the top/left corner of the object
- NewItem.y+=DeltaY; // Y position of the top/left coner of the object
-
- // make sure the object lies within a section
- if (item[OrigItem].type!=GROUP) {
- MakeRect(&CursRect,NewItem.x,NewItem.y,NewItem.width,NewItem.height);
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- NewItem.x=CursRect.left;
- NewItem.y=CursRect.top;
- NewItem.width=CursRect.right-CursRect.left;
- NewItem.height=CursRect.bottom-CursRect.top;
- }
- else { // find section where the group item lies
- for (i=0;i<TotalItems;i++) if (item[i].y>NewItem.y) break;
- if (i>0) CurSec=item[i-1].section;
- else CurSec=item[0].section;
- }
-
- // Insert the item in the item array
- CurItem=FrFindItemSlot(CurSec);// sorted slot where the item will be inserted
-
- NewItem.section=CurSec;
-
- // adjustment for field type items
- if (NewItem.type==FIELD) {
- pField=&field[NewItem.field];
- if (CurSec>=SEC_FTR_LVL9 && item[OrigItem].section<SEC_FTR_LVL9) {
- if ((pField->type==TYPE_NUM || pField->type==TYPE_DBL)
- && pField->source!=SRC_SYS) pField->SumType=SUM_TOTAL;
- }
- if (CurSec<SEC_FTR_LVL9) pField->SumType=SUM_NONE;
- }
-
- // Insert the modified item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
- if (OrigItem>=CurItem) OrigItem++; // scrolled down
-
- // delete the old item
- MoveItemArray(OrigItem,1,'D'); // delete the old item
- if (OrigItem<CurItem) CurItem--; // scroll down
-
- return CurItem;
- }
-
- /******************************************************************************
- SizeItem()
- This routine is called when a mouse button is release as a screen item
- is being sized.
- *******************************************************************************/
- SizeItem()
- {
- int CurItem,CurSec;
- struct StrItem NewItem;
-
- if (item[SelItem].type==SECTION) return SizeSection();
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
-
- // Initialize the NewItem
- HugeMove(&item[SelItem],&NewItem,sizeof(struct StrItem));
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.width=CursRect.right-CursRect.left;
- NewItem.height=CursRect.bottom-CursRect.top;
- if (NewItem.width<1) NewItem.width=1;
- if (NewItem.height<1) NewItem.height=1;
- NewItem.sized=TRUE; // mark as manually sized
- if (NewItem.type==FIELD) CreateFieldLabel(NewItem.field,NewItem.label,NewItem.width,NewItem.font);
-
- // Insert the item in the item array
- CurItem=FrFindItemSlot(CurSec);// sorted slot where the item will be inserted
-
- NewItem.section=CurSec;
-
- // Insert the modified item
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
- if (SelItem>=CurItem) SelItem++; // scrolled down
-
- // delete the old item
- MoveItemArray(SelItem,1,'D'); // delete the old item
- if (SelItem<CurItem) CurItem--; // scroll down
- SelItem=CurItem; // now select the new item
-
- // END
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- SizeSection()
- This routine is called when a mouse button is release as a screen section
- is being sized.
- *******************************************************************************/
- SizeSection()
- {
- int CurSec,i,MinY,MaxY,AdjHeight,AdjY;
- struct StrItem NewItem;
-
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
-
- CurSec=item[SelItem].section; // current section
-
- // Find height of items within this section
- MinY=MaxY=-1;
- for (i=SelItem+1;i<TotalItems;i++) {
- if (item[i].section!=CurSec) break;
- if (item[i].type==GROUP) continue; // do not consider group item for this calculation
- if (MinY==-1) MinY=item[i].y;
- if (item[i].y<MinY) MinY=item[i].y;
- if (MaxY==-1) MaxY=item[i].y+item[i].height;
- if ((item[i].y+item[i].height)>MaxY) MaxY=item[i].y+item[i].height;
- }
- if (MinY!=-1) { // adjust the cursor rectabgle
- MinY-=FormHdr.SecBannerHeight; // reduce by the section banner height
- if (CursRect.top>=MinY) CursRect.top=MinY-1;
- if (CursRect.bottom<=MaxY) CursRect.bottom=MaxY+1;
- }
-
- // Initialize the NewItem
- HugeMove(&item[SelItem],&NewItem,sizeof(struct StrItem));
-
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.height=CursRect.bottom-CursRect.top;
- if (NewItem.height<(3*FormHdr.SecBannerHeight/2)) NewItem.height=3*FormHdr.SecBannerHeight/2;
-
- // Update the section object
- AdjY=NewItem.y-item[SelItem].y; // Y adjustment
- AdjHeight=NewItem.height-item[SelItem].height; // height adjustment
- FrHeight+=AdjHeight; // update the form height
- HugeMove(&NewItem,&(item[SelItem]),sizeof(struct StrItem));
-
- // update the Y position of items within the current section
- for (i=SelItem;i<TotalItems;i++) {
- if (item[i].section>CurSec) break;
- item[i].y-=AdjY; // adjust the height
- if (i>SelItem) { // bound check
- if (item[i].y>=item[SelItem].y+item[SelItem].height)
- item[i].y=item[SelItem].y+item[SelItem].height-1;
- if (item[i].y<item[SelItem].y+FormHdr.SecBannerHeight)
- item[i].y=item[SelItem].y+FormHdr.SecBannerHeight;
- }
- }
-
- // Update the y position of items in the subsequent sections
- for (i=SelItem;i<TotalItems;i++) {
- if (item[i].section==CurSec) continue;
- item[i].y+=AdjHeight; // adjust the height
- }
-
- // END
- // reset the flags
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- FrPaint(); // repaint the screen
-
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- DeleteItem:
- Delete the current item. The current item must not be a 'section' type
- item.
- ******************************************************************************/
- DeleteItem()
- {
- int group=FALSE,CurItem;
-
- if (SelItem<0) return TRUE; // no item selected
- if (item[SelItem].type==SECTION) return DeleteSection();
-
- if (item[SelItem].type==GROUP) {
- MarkGroupItems(); // mark the items in the group
- group=TRUE;
- }
-
- while (TRUE) { // delete each item
- if (group) CurItem=NextGroupItem();
- else CurItem=SelItem;
- if (CurItem<0) break; // all items processed
-
- if (item[CurItem].type==LINE || item[CurItem].type==LABEL) MoveItemArray(CurItem,1,'D');
- else if (item[CurItem].type==PICT) {
- DeleteFrObject(item[CurItem].font); // delete the font/picture object
- MoveItemArray(CurItem,1,'D'); // delete and scroll the item array
- }
- else if (item[CurItem].type==FIELD) {
- DeleteField(item[CurItem].field); // delete the field object from the field array
- MoveItemArray(CurItem,1,'D'); // delete and scroll the item array
- }
-
- if (!group) break; // only one item to process
- }
-
- FrEraseFocusRect(hFrDC,&CursRect);
- SelItem=-1; // disable all sections
- FrPaint();
- FrModified=TRUE;
-
- return TRUE;
- }
-
- /******************************************************************************
- PosItem:
- Position the item text inside the item outlines.
- ******************************************************************************/
- PosItem()
- {
- int result,i,GroupItem;
- UINT flags,mask;
-
- if (SelItem<0) return TRUE; // no item selected
- if (item[SelItem].type!=LABEL && item[SelItem].type!=FIELD && item[SelItem].type!=GROUP) return TRUE; // applicable to label and field only
- if (item[SelItem].type==FIELD && field[item[SelItem].field].type==TYPE_PICT) return TRUE; // picture type item does not use font
-
-
- result=CallDialogBox("PosParam",PosParam,0L);
- if (result) {
- if (item[SelItem].type==GROUP) { // update all items in the group
- GroupItem=SelItem;
- MarkGroupItems(); // mark the items in the group
- // make a mask for the flags to be changed
- mask=OFLAG_HLEFT|OFLAG_HRIGHT|OFLAG_HCENTER|OFLAG_VTOP|OFLAG_VBOTTOM|OFLAG_VCENTER;
- flags=item[GroupItem].flags&mask;
- mask=~mask;
- for (i=0;i<TotalItems;i++) {
- if (item[i].InGroup) {
- if (item[i].type!=LABEL || item[i].type!=FIELD) {
- item[i].flags=(item[i].flags&mask)|flags;
- }
- item[i].InGroup=FALSE;
- }
- }
- }
-
- FrPaint();
- FrModified=TRUE;
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- EditLine:
- Edit current line property
- ******************************************************************************/
- EditLine()
- {
- int result;
-
- if (SelItem<0 || item[SelItem].type!=LINE) return TRUE; // no item selected
-
- result=CallDialogBox("LineParam",LineParam,0L);
- if (result) {
- FrPaint();
- FrModified=TRUE;
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- EditItemOutline:
- Edit the item outline style and color
- ******************************************************************************/
- EditItemOutline()
- {
- int result,i,GroupItem;
-
- if (SelItem<0) return TRUE; // no item selected
-
- result=CallDialogBox("OutlineParam",OutlineParam,0L);
- if (result) {
- if (item[SelItem].type==GROUP) { // update all items in the group
- GroupItem=SelItem;
- MarkGroupItems(); // mark the items in the group
- for (i=0;i<TotalItems;i++) {
- if (item[i].InGroup) {
- item[i].OutlineSelect=item[GroupItem].OutlineSelect;
- item[i].OutlineStyle =item[GroupItem].OutlineStyle;
- item[i].OutlineWidth =item[GroupItem].OutlineWidth;
- item[i].OutlineColor =item[GroupItem].OutlineColor;
- item[i].InGroup=FALSE;
- }
- }
- }
-
- FrPaint();
- FrModified=TRUE;
- }
-
-
- return TRUE;
- }
-
- /******************************************************************************
- EditItemBackground:
- Edit the item background paiting brush
- ******************************************************************************/
- EditItemBackground()
- {
- int result,i,GroupItem;
- UINT flags,mask;
-
- if (SelItem<0) return TRUE; // no item selected
- if (item[SelItem].type==PICT) return TRUE; // not applicable for picture type objects
-
- result=CallDialogBox("BackgroundParam",BackgroundParam,0L);
- if (result) {
- if (item[SelItem].type==GROUP) { // update all items in the group
- GroupItem=SelItem;
- MarkGroupItems(); // mark the items in the group
- // make a mask for the flags to be changed
- mask=OFLAG_FILL;
- flags=item[GroupItem].flags&mask;
- mask=~mask;
- for (i=0;i<TotalItems;i++) {
- if (item[i].InGroup) {
- if (item[i].type!=PICT) { // N/A
- item[i].flags=(item[i].flags&mask)|flags;
- HugeMove(&(item[GroupItem].brush),&(item[i].brush),sizeof(LOGBRUSH));
- }
- item[i].InGroup=FALSE;
- }
- }
- }
- FrPaint();
- FrModified=TRUE;
- }
- return TRUE;
- }
-
- /******************************************************************************
- CenterItem:
- Center the selected item horizontally.
- *******************************************************************************/
- CenterItem()
- {
- int CurSec,SecItem;
- RECT rect;
-
- if (SelItem<0 || item[SelItem].type==SECTION) return TRUE;
-
- // get the current section
- CurSec=item[SelItem].section;
- SecItem=section[CurSec].ScrItem;
-
- // build the new item position
- rect.left=item[SecItem].x+(item[SecItem].width-item[SelItem].width)/2;
- rect.right=rect.left+item[SelItem].width;
- rect.top=item[SelItem].y;
- rect.bottom=rect.top+item[SelItem].height;
-
- // scroll the screen if necessary
- FrEraseFocusRect(hFrDC,&CursRect);
- FarMove(&rect,&CursRect,sizeof(RECT));
- FrAdjustScroll(&CursRect);
- MoveItem(); // move the item to the new location
-
- return TRUE;
- }
-
- /******************************************************************************
- SelectGroupItemPartI()
- This routine initiates group item selection. It defines a cursor rectangle
- for the group item. When the user releases the mouse button, the
- SelectGroupItemPartII function is used to position the group item
- rectangle at the current location.
- *******************************************************************************/
- SelectGroupItemPartI(int x,int y)
- {
- if (MouseX==x && MouseY==y) return TRUE; // no mouse movement yet
-
- // deselect currently selected item
- if (SelItem>=0) DeselectItem(); // deselect the current item
-
- // define the cursor rectangle
- CursRect.left=MouseX;
- CursRect.right=x;
- CursRect.top=MouseY;
- CursRect.bottom=y;
-
- // Draw the focus rectangle
- FrDrawFocusRect(hFrDC,&CursRect);
-
- // set the flags
- CurCmd=ID_SELECT_MULTIPLE; // current unfinished command
- IgnoreMouseMove=FALSE; // monitor mouse movements now
- SelItem=-1; // no item selected yet
- CurTab=TAB_SE; // let the rectangle be stretched
-
- return TRUE;
- }
-
- /******************************************************************************
- SelectGroupItemPartII:
- This routine is called when the group item cursor is clicked. It position
- the group item at the current cursor location.
- *******************************************************************************/
- SelectGroupItemPartII()
- {
- int CurItem,CurSec,GroupItem,i;
- struct StrItem NewItem;
-
- // locate the previous group item
- for (GroupItem=0;GroupItem<TotalItems;GroupItem++) if (item[GroupItem].type==GROUP) break;
- if (GroupItem>=TotalItems) AbortFr("Group Item Missing",ERR_OTHER);
-
- // make a copy of the previous group item and delete previous group item
- HugeMove(&item[GroupItem],&NewItem,sizeof(struct StrItem));
- MoveItemArray(GroupItem,1,'D'); // delete this item
-
- // find the location for the new group item
- FrEraseFocusRect(hFrDC,&CursRect);// erase the focus rectangle
- CurSec=FrAdjustCursorRect(); // adjust the cursor rectangle position
- CurItem=FrFindItemSlot(CurSec); // slot where the item will be inserted
-
- // assign the group item fields.
- if (CursRect.left<CursRect.right) {
- NewItem.x=CursRect.left; // X position of the top/left corner of the object
- NewItem.width=CursRect.right-CursRect.left; // width of the object
- }
- else {
- NewItem.x=CursRect.right; // X position of the top/left corner of the object
- NewItem.width=CursRect.left-CursRect.right; // width of the object
- }
- if (CursRect.top<CursRect.bottom) {
- NewItem.y=CursRect.top; // Y position of the top/left coner of the object
- NewItem.height=CursRect.bottom-CursRect.top;// height of the object
- }
- else {
- NewItem.y=CursRect.bottom; // Y position of the top/left coner of the object
- NewItem.height=CursRect.top-CursRect.bottom;// height of the object
- }
- NewItem.section=CurSec; // Current section
-
- MoveItemArray(CurItem,1,'B'); // scroll down the array
- HugeMove(&NewItem,&(item[CurItem]),sizeof(struct StrItem));
- SelItem=CurItem; // select the current group item
- // Do not select very small selection rectangle
- if (NewItem.width<=DESC_MARGIN && NewItem.height<=DESC_MARGIN) {
- CurSec=item[SelItem].section;
- SelItem=section[CurSec].ScrItem;
- }
-
- // reset the item selection flag
- for (i=0;i<TotalItems;i++) item[i].flags=ResetUintFlag(item[i].flags,OFLAG_SELECT_TOGGLE);
-
- CurCmd=-1; // currnet command completed
- IgnoreMouseMove=TRUE;
- SetCursor(hArrowCursor); // set the regular cursor
- FrPaint(); // repaint the screen
-
- return TRUE;
- }
-
- /******************************************************************************
- AlignHorzTop:
- Align horizontally at the top edge of the selected items.
- *******************************************************************************/
- void AlignHorzTop()
- {
- int i,LeadItem,DeltaVal,CurItem,FixVal;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the leftmost item
- if ((LeadItem=LeftMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].y; // set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-item[CurItem].y; // amount of adjustment
- MoveEachItem(CurItem,0,DeltaVal);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- AlignHorzBot:
- Align horizontally at the bottom edge of the selected items.
- *******************************************************************************/
- void AlignHorzBot()
- {
- int i,LeadItem,DeltaVal,CurItem,FixVal;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the leftmost item
- if ((LeadItem=LeftMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].y+item[LeadItem].height; // set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-(item[CurItem].y+item[CurItem].height); // amount of adjustment
- MoveEachItem(CurItem,0,DeltaVal);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- AlignHorzCenter:
- Align horizontally at the center line of the selected items.
- *******************************************************************************/
- void AlignHorzCenter()
- {
- int i,LeadItem,DeltaVal,FixVal,CurItem;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the leftmost item
- if ((LeadItem=LeftMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].y+item[LeadItem].height/2; // set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-(item[CurItem].y+item[CurItem].height/2); // amount of adjustment
- MoveEachItem(CurItem,0,DeltaVal);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- AlignVertLeft:
- Align vertically at the left edge of the selected items.
- *******************************************************************************/
- void AlignVertLeft()
- {
- int i,LeadItem,DeltaVal,CurItem,FixVal;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the topmost item
- if ((LeadItem=TopMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].x; // set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-item[CurItem].x; // amount of adjustment
- MoveEachItem(CurItem,DeltaVal,0);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- AlignVertRight:
- Align vertically at the right edge of the selected items.
- *******************************************************************************/
- void AlignVertRight()
- {
- int i,LeadItem,DeltaVal,CurItem,FixVal;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the topmost item
- if ((LeadItem=TopMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].x+item[LeadItem].width;// set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-(item[CurItem].x+item[CurItem].width); // amount of adjustment
- MoveEachItem(CurItem,DeltaVal,0);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- AlignVertCenter:
- Align vertically at the vertical center line.
- *******************************************************************************/
- void AlignVertCenter()
- {
- int i,LeadItem,DeltaVal,CurItem,FixVal;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead item as the topmost item
- if ((LeadItem=TopMostItem())<0) return;
- item[LeadItem].InGroup=FALSE; // do not move the lead item
- FixVal=item[LeadItem].x+item[LeadItem].width/2;// set at this value
-
- // do the alignment
- while(TRUE) {
- if ((CurItem=NextGroupItem())<0) break; // all items processed
- DeltaVal=FixVal-(item[CurItem].x+item[CurItem].width/2); // amount of adjustment
- MoveEachItem(CurItem,DeltaVal,0);
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- EvenSpaceHorz:
- Place the selected items at equal horinzontal distances.
- *******************************************************************************/
- void EvenSpaceHorz()
- {
- int i,LeadItem,SecondItem,DeltaVal,CurItem,NextPos,distance;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead and the second items from the left
- if ((LeadItem=LeftMostItem())<0) return; // no more items
- item[LeadItem].InGroup=FALSE; // remove this item from the list
- if ((SecondItem=LeftMostItem())<0) return; // no more items
-
- // Calculate the distance
- distance=item[SecondItem].x-(item[LeadItem].x+item[LeadItem].width);
- if (distance<0) distance=0;
- NextPos=item[LeadItem].x+item[LeadItem].width+distance;
-
- // Set the position of items starting from the second item
- while(TRUE) {
- if ((CurItem=LeftMostItem())<0) break; // all items processed
- item[CurItem].InGroup=FALSE; // remove this item from the list
- DeltaVal=NextPos-item[CurItem].x; // amount of adjustment
- CurItem=MoveEachItem(CurItem,DeltaVal,0);
- NextPos=item[CurItem].x+item[CurItem].width+distance;
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- EvenSpaceVert:
- Place the selected items at equal vertical distances.
- *******************************************************************************/
- void EvenSpaceVert()
- {
- int i,LeadItem,SecondItem,DeltaVal,CurItem,NextPos,distance;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead and the second items from the left
- if ((LeadItem=TopMostItem())<0) return; // no more items
- item[LeadItem].InGroup=FALSE; // remove this item from the list
- if ((SecondItem=TopMostItem())<0) return; // no more items
-
- // Calculate the distance
- distance=item[SecondItem].y-(item[LeadItem].y+item[LeadItem].height);
- if (distance<0) distance=0;
- NextPos=item[LeadItem].y+item[LeadItem].height+distance;
-
- // Set the position of items starting from the second item
- while(TRUE) {
- if ((CurItem=TopMostItem())<0) break; // all items processed
- item[CurItem].InGroup=FALSE; // remove this item from the list
- DeltaVal=NextPos-item[CurItem].y; // amount of adjustment
- CurItem=MoveEachItem(CurItem,0,DeltaVal);
- NextPos=item[CurItem].y+item[CurItem].height+distance;
- }
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- EvenSizeHorz:
- Set the same width (as the first item) for all items in the group
- *******************************************************************************/
- void EvenSizeHorz()
- {
- int i,LeadItem,width;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead and the second items from the left
- if ((LeadItem=LeftMostItem())<0) return; // no more items
- item[LeadItem].InGroup=FALSE; // remove this item from the list
- width=item[LeadItem].width; // width of the lead item
-
- // Set the width of the remaining items
- PaintEnabled=FALSE; // disable the painting until all items sized
- while(TRUE) {
- if ((SelItem=NextGroupItem())<0) break; // all items processed
-
- // Construct the temporary size cursor
- CursRect.left=item[SelItem].x;
- CursRect.right=item[SelItem].x+width; // add the width of the lead item
- CursRect.top=item[SelItem].y;
- CursRect.bottom=item[SelItem].y+item[SelItem].height;
- SizeItem(); //size this item
- }
- PaintEnabled=TRUE; //enable painting
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- EvenSizeVert:
- Set the same height (as the first item) for all items in the group
- *******************************************************************************/
- void EvenSizeVert()
- {
- int i,LeadItem,height;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return;
-
- StoreUndo(); // store the undo data
-
- MarkGroupItems(); // mark the items in this group
-
- // find the lead and the second items from the left
- if ((LeadItem=LeftMostItem())<0) return; // no more items
- item[LeadItem].InGroup=FALSE; // remove this item from the list
- height=item[LeadItem].height; // height of the lead item
-
- // Set the width of the remaining items
- PaintEnabled=FALSE; // disable the painting until all items sized
- while(TRUE) {
- if ((SelItem=NextGroupItem())<0) break; // all items processed
-
- // Construct the temporary size cursor
- CursRect.left=item[SelItem].x;
- CursRect.right=item[SelItem].x+item[SelItem].width;
- CursRect.top=item[SelItem].y;
- CursRect.bottom=item[SelItem].y+height; // add the height of the lead item
- SizeItem(); //size this item
- }
- PaintEnabled=TRUE; //enable painting
-
- // find the group item
- for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
- if (i<TotalItems) SelItem=i;
- FrModified=TRUE;
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- ExpandHorizontal:
- Move all items to the right of the selection rectangle toward right by the
- width of the selection rectangle
- *******************************************************************************/
- int ExpandHorizontal()
- {
- int i,x,y,height,width;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return TRUE;
-
- x=item[SelItem].x;
- y=item[SelItem].y;
- width=item[SelItem].width;
- height=item[SelItem].height;
-
- // process each item
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==SECTION || item[i].type==GROUP) continue;
- if (item[i].x<x) continue; // do not move items left of the selection rectangle
- if (item[i].y+item[i].height<y) continue; // do not move items above the rectangle
- if (item[i].y>y+height) continue; // do not move items below the rectangle
-
- item[i].x+=width; // move item
- }
-
- FrModified=TRUE;
- FrPaint();
-
- return TRUE;
- }
-
- /******************************************************************************
- CompressHorizontal:
- Move all items to the right of the selection rectangle toward left by the
- width of the selection rectangle. This function is ignored when an item
- is found within the rectangle
- *******************************************************************************/
- int CompressHorizontal()
- {
- int i,x,y,height,width;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return TRUE;
-
- x=item[SelItem].x;
- y=item[SelItem].y;
- width=item[SelItem].width;
- height=item[SelItem].height;
-
- // check if an item lies within the selection rectangle
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==SECTION || item[i].type==GROUP) continue;
- if (item[i].y+item[i].height<y) continue; // do not move items above the rectangle
- if (item[i].y>y+height) continue; // do not move items below the rectangle
-
- if (item[i].x>=x && item[i].x<=x+width) {
- MessageBeep(0);
- return TRUE;
- }
- }
-
- // process each item
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==SECTION || item[i].type==GROUP) continue;
- if (item[i].x<x) continue; // do not move items left of the selection rectangle
- if (item[i].y+item[i].height<y) continue; // do not move items above the rectangle
- if (item[i].y>y+height) continue; // do not move items below the rectangle
-
- item[i].x-=width; // move item
- }
-
- FrModified=TRUE;
- FrPaint();
-
- return TRUE;
- }
-
- /******************************************************************************
- ExpandVertical:
- Move all items below the selection rectangle toward bottom by the
- height of the selection rectangle
- *******************************************************************************/
- int ExpandVertical()
- {
- int i,y,height,CurSec;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return TRUE;
-
- y=item[SelItem].y;
- height=item[SelItem].height;
- CurSec=item[SelItem].section;
-
- // process each item
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==GROUP) continue;
- if (item[i].y<y) continue; // do not move items above the rectangle
-
- item[i].y+=height; // move item
- }
-
- // update the section and form height
- item[section[CurSec].ScrItem].height+=height; // expand the current section
- FrHeight+=height; // expand the form
-
- FrModified=TRUE;
- FrPaint();
-
- return TRUE;
- }
-
- /******************************************************************************
- CompressVertical:
- Move all items below the selection rectangle upward by the
- height of the selection rectangle. This function is not effective if an
- item is found within the horizontal band of the selection rectangle
- *******************************************************************************/
- int CompressVertical()
- {
- int i,y,height,CurSec;
-
- // exit if a group item not selected
- if (SelItem<0 || item[SelItem].type!=GROUP) return TRUE;
-
- y=item[SelItem].y;
- height=item[SelItem].height;
- CurSec=item[SelItem].section;
-
- // check if an item lies in the horizontal band of the selection rectangle
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==SECTION || item[i].type==GROUP) continue;
- if (item[i].y>=y && item[i].y<=y+height) {
- MessageBeep(0);
- return TRUE;
- }
- }
-
- // process each item
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==GROUP) continue;
- if (item[i].y<y) continue; // do not move items above the rectangle
-
- if (item[i].type==SECTION && item[i].section==CurSec) continue;
-
- item[i].y-=height; // move item
- }
-
- // update the section and form height
- item[section[CurSec].ScrItem].height-=height; // compress the current section
- FrHeight-=height; // compress the form
-
- FrModified=TRUE;
- FrPaint();
-
- return TRUE;
- }
-
-
- /******************************************************************************
- StoreUndo:
- Store the item data that can be undone later
- *******************************************************************************/
- void StoreUndo()
- {
- long size;
-
- if (UndoItem) DiscardUndo(); // discard the previous undo
-
- // allocate memory for undo
- if ((size=(long)TotalItems*(long)sizeof(struct StrItem))>32000) return; // too large
- if (NULL==(UndoItem=OurAlloc((UINT)size))) return;
-
- HugeMove(item,UndoItem,(UINT)size);
- TotalUndoItems=TotalItems;
- }
-
- /******************************************************************************
- DiscardUndo:
- Discard the undo data for the previous command.
- *******************************************************************************/
- void DiscardUndo()
- {
- if (UndoItem) {
- OurFree(UndoItem);
- UndoItem=NULL;
- }
- }
-
- /******************************************************************************
- Undo:
- Undo the previous arrange command
- *******************************************************************************/
- void Undo()
- {
- UINT size;
- int i,CurSec;
-
- if (!UndoItem || TotalUndoItems!=TotalItems) {
- DiscardUndo();
- return;
- }
-
- // restore previous items
- size=(UINT)TotalItems*(UINT)sizeof(struct StrItem);
-
- HugeMove(UndoItem,item,(UINT)size);
- DiscardUndo(); //now discard the undo data
-
- // fix the section reference
- for (i=0;i<TotalItems;i++) {
- if (item[i].type==SECTION) {
- CurSec=item[i].section;
- section[CurSec].ScrItem=i; //reference to the item number
- }
- else if (item[i].type==GROUP) SelItem=i;
- }
- FrPaint(); // refresh the screen
- }
-
- /******************************************************************************
- FrWinUp()
- Scroll the window up by one character.
- *******************************************************************************/
- FrWinUp()
- {
- if (FrWinOrgY>0) {
- FrWinOrgY-=FrFont[DEFAULT_CFMT].height;
- PaintFlag=PAINT_WIN;
- FrPaint();
- }
- return TRUE;
- }
-
- /******************************************************************************
- FrWinDown:
- Scroll the window down by one character.
- *******************************************************************************/
- FrWinDown()
- {
- if (FrWinOrgY<FrHeight) {
- FrWinOrgY+=FrFont[DEFAULT_CFMT].height;
- PaintFlag=PAINT_WIN;
- FrPaint();
- }
- return TRUE;
- }
-
- /******************************************************************************
- FrWinRight:
- Scroll the window right by one character
- *******************************************************************************/
- FrWinRight()
- {
- if (FrWinOrgX<FrWidth) {
- FrWinOrgX+=FrFont[DEFAULT_CFMT].height;
- PaintFlag=PAINT_WIN;
- FrPaint();
- }
- return TRUE;
- }
-
- /******************************************************************************
- FrWinLeft:
- Scroll the window left by one character
- *******************************************************************************/
- FrWinLeft()
- {
- if (FrWinOrgX>0) {
- FrWinOrgX-=FrFont[DEFAULT_CFMT].height;
- PaintFlag=PAINT_WIN;
- FrPaint();
- }
- return TRUE;
- }
-
- /******************************************************************************
- MoveItemArray:
- Use this routine to insert or delete elements from the item array.
- Parameters #1 and #2 specify the range of elements to insert or delete.
- Parameter #3 specifies the request type:
- 'D' : Delete the array elements
- 'A' : Insert after the start line element.
- 'B' : Insert before the start line element.
- The calling routine must ensure that final item count does not exceed
- MaxLines.
- This routine WILL update the TotalLines variable and will update
- the 'ScrItem' reference in the section array for the scolled sections.
- ******************************************************************************/
- void MoveItemArray(int StartItem,int count,char InsertDel)
- {
- int i,CurSec,BeginFix;
-
- if (InsertDel=='A') { // insert after the start line
- if (TotalItems-StartItem-1>0) {
- HugeMove(&item[StartItem+1],&item[StartItem+count+1],(TotalItems-StartItem-1)*(long)(sizeof (struct StrItem))); // make space for new item
- }
- TotalItems=TotalItems+count;
- BeginFix=StartItem+count+1; // begin the fix at the first scrolled down item
- }
- else if (InsertDel=='B') { // insert before the start line
- HugeMove(&item[StartItem],&item[StartItem+count],(TotalItems-StartItem)*(long)(sizeof (struct StrItem))); // make space for new lines
- TotalItems=TotalItems+count;
- BeginFix=StartItem+count;
- }
- else { // delete the elements
- if (TotalItems-StartItem-count>0) {
- HugeMove(&item[StartItem+count],&item[StartItem],(TotalItems-StartItem-count)*(long)(sizeof (struct StrItem))); // make space for new lines
- }
- TotalItems=TotalItems-count;
- BeginFix=StartItem;
- }
-
- // fix the section reference
- for (i=BeginFix;i<TotalItems;i++) {
- if (item[i].type==SECTION) {
- CurSec=item[i].section;
- section[CurSec].ScrItem=i; //reference to the item number
- }
- }
-
- }
-
- /*****************************************************************************
- CallDialogBox:
- This function call a modal dialog box, and returns an interger result
- ******************************************************************************/
- int CallDialogBox(LPSTR template,DLGPROC lpProc,DWORD lParam)
- {
- int result;
-
- lpProc = (DLGPROC) MakeProcInstance((FARPROC)lpProc, hFrInst);
- result=DialogBoxParam(hFrInst,template,hFrWnd,lpProc,lParam);
- FreeProcInstance((FARPROC)lpProc); // set back the old window
-
- if (SessionType=='F') {
- SetFocus(hFrWnd);
- }
- return result;
- }
-
-