home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-26 | 37.3 KB | 1,075 lines | [TEXT/KAHL] |
- $$Loop Windows
- $$Message MM Window, mm:mmW_$Worksheet.name$.c
-
- $$File mm:mmW_$Worksheet.name$.c
- /* mmW_$Worksheet.name$ Handle this Window */
- /* $CopyRight$ */
-
- /*
- File name: mmW_$Worksheet.name$.c
- Function: Handle a Window
- History: $Date$ Original by $Author$
-
- */
-
- #include "mmCommon$Prototype.name$.h" /* Common */
- #include "Common$Prototype.name$.h" /* Common */
-
- #include "$Worksheet.name$.h" /* The window specific file */
-
- /* ======================================================= */
-
- static void InitRecord($Worksheet.name$RecPtr theWS);
-
- static void LocateInstance(WindowPtr theWindow);
-
- /* Handle a button being pressed */
- static void Do_A_Button($Worksheet.name$RecPtr theWS,ControlHandle theControl);
-
- $$if Worksheet.CheckboxesOrRadios
- /* Handle a checkbox being pressed */
- static void Do_A_Checkbox($Worksheet.name$RecPtr theWS,ControlHandle theControl);
-
- $$endif
- $$if Worksheet.Scrollbars
- /* Handle a ScrollBar being pressed */
- static void Do_A_ScrollBar($Worksheet.name$RecPtr theWS,short code, ControlHandle theControl, Point myPt);
-
- /* ======================================================= */
- /* ======================================================= */
-
- /* Routine: Do_A_ScrollBar */
- /* Purpose: Handle a ScrollBar being pressed */
-
- static void Do_A_ScrollBar($Worksheet.name$RecPtr theWS,short code,ControlHandle theControl,Point myPt)
- {
- long RefCon; /* RefCon for controls */
-
-
- RefCon = GetCRefCon(theControl); /* get control refcon */
-
- U_Scroll$Worksheet.name$(theWS,&RefCon,code, &myPt); /* Allow for special handling of scrollbars */
-
- switch (RefCon) /* Select correct scrollbar */
- {
- $$Loop Control.type = ScrollBar
- case ResC_$Control.name$: /* Scroll bar, $Control.FullName$ */
- HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/* code,Inc,PageInc,handle */
- break;
-
- $$EndLoop
- $$Loop Control.type = UGauge
- case ResC_$Control.name$: /* Plugin gauge, $Control.FullName$ */
- HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/* code,Inc,PageInc,handle */
- break;
-
- $$EndLoop
- $$if Worksheet.Document
- $$if Worksheet.ScrollHorz
- case 12345L:
- HandleWScrollBar(myPt,code,1,10,theControl);
- break;
-
- $$endif
- $$if Worksheet.ScrollVert
- case 12346L:
- HandleWScrollBar(myPt,code,1,10,theControl);
- break;
-
- $$endif
- $$endif Worksheet.Document
- default: /* allow other buttons, trap for debug */
- break; /* end of otherwise */
- } /* end of switch */
- }
-
- $$endif
- /* ======================================================= */
- /* ======================================================= */
-
- static void InitRecord($Worksheet.name$RecPtr theWS)
- {
-
-
- theWS->theWindow = nil; /* Make sure other routines know we are not valid yet */
-
- $$if Worksheet.Document
- $$if Worksheet.ScrollHorz
- theWS->ScrollHHandle = nil; /* Scrollbar is not valid yet */
- theWS->ScrollHLeftOffset = -1; /* Offset of control from left side */
- $$endif
- $$if Worksheet.ScrollVert
- theWS->ScrollVHandle = nil; /* Scrollbar is not valid yet */
- theWS->ScrollVTopOffset = -1; /* Offset of control from top edge */
- $$endif
- $$endif Worksheet.Document
- /* Set the window back color */
- theWS->WindowBackColor.red = 0x$Worksheet.RedBackColor$;
- theWS->WindowBackColor.green = 0x$Worksheet.GreenBackColor$;
- theWS->WindowBackColor.blue = 0x$Worksheet.BlueBackColor$;
-
- $$Loop Control.type = Button
- theWS->Enable_$Control.name$ = $Control.Active$; /* Button, $Control.FullName$ */
- $$EndLoop
- $$Loop Control.type = HotRect
- $$if Control.HotSpot
- theWS->Enable_$Control.name$ = $Control.Active$; /* HotSpot, $Control.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Control.type = Checkbox
- theWS->Enable_$Control.name$ = $Control.Active$; /* Checkbox, $Control.FullName$ */
- $$if Control.Selected
- theWS->Value_$Control.name$ = 1;
- $$endif
- $$if Control.Unselected
- theWS->Value_$Control.name$ = 0;
- $$endif
- $$EndLoop
- $$Loop Control.type = Radio
- theWS->Enable_$Control.name$ = $Control.Active$; /* Radio, $Control.FullName$ */
- $$if Control.Selected
- theWS->Value_$Control.name$ = 1;
- $$endif
- $$if Control.Unselected
- theWS->Value_$Control.name$ = 0;
- $$endif
- $$EndLoop
- $$Loop Control.type = ScrollBar
- theWS->Enable_$Control.name$ = $Control.Active$; /* ScrollBar, $Control.FullName$ */
- theWS->Value_$Control.name$ = $Control.ValueScroll$;
- $$EndLoop
- $$Loop Control.type = Icon
- $$if Control.NonGraphic
- theWS->Enable_$Control.name$ = $Control.Active$; /* Icon button, $Control.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Control.type = Sicn
- $$if Control.NonGraphic
- theWS->Enable_$Control.name$ = $Control.Active$; /* Sicn button, $Control.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Control.type = Picture
- $$if Control.NonGraphic
- theWS->Enable_$Control.name$ = $Control.Active$; /* Picture button, $Control.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Control.type = UButton
- theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin button, $Control.FullName$ */
- $$EndLoop
- $$Loop Control.type = UToggle
- theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin toggle, $Control.FullName$ */
- $$if Control.Selected
- theWS->Value_$Control.name$ = 1;
- $$endif
- $$if Control.Unselected
- theWS->Value_$Control.name$ = 0;
- $$endif
- $$EndLoop
- $$Loop Control.type = UGauge
- theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin gauge, $Control.FullName$ */
- theWS->Value_$Control.name$ = $Control.ValueScroll$;
- $$EndLoop
- $$Loop Control.type = Popup
- theWS->Enable_$Control.name$ = $Control.Active$; /* Popup menu, $Control.FullName$ */
- theWS->Value_$Control.name$ = $Control.SelectedID$;
- $$EndLoop
- $$Loop Control.type = Palette
- theWS->Enable_$Control.name$ = $Control.Active$; /* Palette, $Control.FullName$ */
- theWS->Value_$Control.name$ = $Control.ValueScroll$;
- $$EndLoop
- $$Loop Control.type = List
- theWS->List_$Control.name$ = nil; /* List, $Control.FullName$ */
- SetRect(&theWS->ListRect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$); /* left,top,right,bottom */
- $$EndLoop
- $$Loop Control.type = EditText
- theWS->TE_$Control.name$ = nil; /* Edit Text, $Control.FullName$ */
- SetRect(&theWS->TERect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$); /* left,top,right,bottom */
- GetIndString(theWS->TEStr_$Control.name$,sResC_$Control.name$,1);/* ...Edit text, default value */
- $$EndLoop
-
- U_Init$Worksheet.name$Rec(theWS); /* Call user init routine */
- }
-
- /* ======================================================= */
-
- static void LocateInstance(WindowPtr theWindow)
- {
- $Worksheet.name$RecPtr ckWS,theWS;
-
-
- theWS = nil; /* Init to not found */
- ckWS = ListRecPtr_$Worksheet.name$;
- while (ckWS != nil)
- {
- if (ckWS->theWindow == theWindow)
- theWS = ckWS;
- ckWS = ckWS->Next;
- }
- RecPtr_$Worksheet.name$ = theWS;
- }
-
- /* ======================================================= */
-
- /* Routine: Init_$Worksheet.name$ */
- /* Purpose: Initialize our window data to not in use yet */
-
- void Init_$Worksheet.name$(void)
- {
-
-
- $$if Worksheet.SavePosition
- theWindowLocRec.Loc_$Worksheet.name$.h = $Worksheet.LeftPosition$; /* Set default Horz position */
- theWindowLocRec.Loc_$Worksheet.name$.v = $Worksheet.TopPosition$; /* Set default Vert position */
-
- $$endif Worksheet.SavePosition
- RecPtr_$Worksheet.name$ = nil; /* No open windows yet */
- ListRecPtr_$Worksheet.name$ = nil;
- MultipleAllowed_$Worksheet.name$ = true; /* Init to allow multiple instances */
-
- U_Init$Worksheet.name$(); /* Call the user window init routine */
- }
-
- /* ======================================================= */
-
- /* Routine: Close_$Worksheet.name$ */
- /* Purpose: Close out the window */
-
- void Close_$Worksheet.name$(WindowPtr whichWindow)
- {
- $Worksheet.name$RecPtr ckWS,theWS;
-
-
- if (whichWindow == (WindowPtr)-1)
- whichWindow = FrontWindow();
-
- LocateInstance(whichWindow);
-
- /* See if we should close this window */
- if (RecPtr_$Worksheet.name$ != nil)
- {
- theWS = RecPtr_$Worksheet.name$;
-
- U_Close$Worksheet.name$(theWS); /* Call the user window close routine */
-
- $$Loop Control.type = EditText
- if (theInput == theWS->TE_$Control.name$) /* See if this Text Edit field handle */
- theInput = nil; /* Clear the handle used */
- $$if Control.Global
- Get_TE_String(theWS->TE_$Control.name$,(Str255 *)&theWS->TEStr_$Control.name$);
- $$endif Control.Global
- TEDispose(theWS->TE_$Control.name$); /* Dispose of a List, $Control.FullName$ */
-
- $$EndLoop
- $$Loop Control.type = List
- LDispose(theWS->List_$Control.name$); /* Dispose of a List, $Control.FullName$ */
-
- $$EndLoop
- $$if Worksheet.SavePosition
- SetPort(whichWindow); /* Select our window */
- theWindowLocRec.Loc_$Worksheet.name$.h = 0; /* Reset Horz position */
- theWindowLocRec.Loc_$Worksheet.name$.v = 0; /* Reset Vert position */
- LocalToGlobal(&theWindowLocRec.Loc_$Worksheet.name$); /* Get global location */
-
- $$endif Worksheet.SavePosition
- Mk_CloseLayeredWindow(whichWindow); /* Notify the layer code that we are closing */
-
- DisposeWindow(whichWindow); /* Clear window and controls */
-
-
- ckWS = ListRecPtr_$Worksheet.name$;
- if (ckWS == theWS) /* See if first in the list */
- {
- ListRecPtr_$Worksheet.name$ = theWS->Next; /* Use second one as new first */
- DisposePtr((Ptr)theWS); /* Get rid of this one */
- }
- else
- {
- while (ckWS != nil) /* Loop thru them all */
- {
- if (ckWS->Next == theWS) /* See if the next one is a match */
- {
- ckWS->Next = theWS->Next; /* Get new next one */
- DisposePtr((Ptr)theWS); /* Get rid of this one */
- ckWS = nil; /* Get us out of the loop */
- }
- else
- ckWS = ckWS->Next; /* Try the next one */
- }
- }
-
- RecPtr_$Worksheet.name$ = nil; /* No active one */
-
- $$Link Worksheet.Close
- }
- }
-
- /* ======================================================= */
-
- /* Routine: Resized_$Worksheet.name$ */
- /* Purpose: We were resized or zoomed, update the scrolling scrollbars */
-
- void Resized_$Worksheet.name$(Rect *OldRect,WindowPtr whichWindow)
- {
- WindowPtr SavePort; /* Place to save the last port */
- Rect temp2Rect; /* temp rectangle */
- short Index; /* temp integer */
- ControlHandle ScrollHandle;
- $Worksheet.name$RecPtr theWS;
-
-
- LocateInstance(whichWindow);
-
- if (RecPtr_$Worksheet.name$ != nil) /* Only do if the window is us */
- {
- theWS = RecPtr_$Worksheet.name$;
-
- GetPort(&SavePort); /* Save the current port */
- SetPort(whichWindow); /* Set the port to my window */
-
- U_Resized$Worksheet.name$(theWS,OldRect); /* Call the user window resized routine */
-
- $$if Worksheet.Document
- temp2Rect = theWS->theWindow->portRect; /* Get the window rectangle */
- EraseRect(&temp2Rect); /* Erase the new window area */
- InvalRect(&temp2Rect); /* Set to update the new window area */
-
- $$if Worksheet.ScrollHorz
- if (theWS->ScrollHHandle != nil) /* Only do if the control is valid */
- {
- ScrollHandle = theWS->ScrollHHandle;
- HLock((Handle)ScrollHandle); /* Lock the handle while we use it */
- tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
- tempRect.top = tempRect.top - 4; /* Widen the area to update */
- tempRect.right = tempRect.right + 16; /* Widen the area to update */
- InvalRect(&tempRect); /* Flag old position for update routine */
- tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
- temp2Rect = whichWindow->portRect; /* Get the window rectangle */
- Index = temp2Rect.right - temp2Rect.left - 13;/* Get the scroll area width */
- tempRect.left = theWS->ScrollHLeftOffset;
- HideControl(ScrollHandle); /* Hide it during size and move */
- SizeControl(ScrollHandle, Index,16); /* Make it 16 pixels high, std width */
- MoveControl(ScrollHandle,tempRect.left,temp2Rect.bottom - temp2Rect.top-15);/* Size it correctly */
- ShowControl(ScrollHandle); /* Safe to show it now */
- HUnlock((Handle)ScrollHandle); /* Let it float again */
- }
-
- $$endif
- $$if Worksheet.ScrollVert
- if (theWS->ScrollVHandle != nil) /* Only do if the control is valid */
- {
- ScrollHandle = theWS->ScrollVHandle;
- HLock((Handle)ScrollHandle); /* Lock the handle while we use it */
- tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
- tempRect.left = tempRect.left - 4; /* Widen the area to update */
- tempRect.bottom = tempRect.bottom + 16; /* Widen the area to update */
- InvalRect(&tempRect); /* Flag old position for update routine */
- tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
- temp2Rect = whichWindow->portRect; /* Get the window rectangle */
- Index = temp2Rect.bottom - temp2Rect.top - 13;/* Get the scroll area height */
- tempRect.top = theWS->ScrollVTopOffset;
- HideControl(ScrollHandle); /* Hide it during size and move */
- SizeControl(ScrollHandle,16,Index); /* Make it 16 pixels high, std height */
- MoveControl(ScrollHandle,temp2Rect.right - temp2Rect.left-15,tempRect.top);/* Size it correctly */
- ShowControl(ScrollHandle); /* Safe to show it now */
- HUnlock((Handle)ScrollHandle); /* Let it float again */
- }
-
- $$endif
- $$endif Worksheet.Document
- SetPort(SavePort); /* Restore the old port */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: Update_$Worksheet.name$ */
- /* Purpose: Update our window */
-
- void Update_$Worksheet.name$(WindowPtr whichWindow)
- {
- WindowPtr SavePort; /* Place to save the last port */
- $$if Worksheet.Icons
- Handle Icon_Handle; /* Handle used in displaying icons */
- $$endif Worksheet.Icons
- $$if Worksheet.Pictures
- PicHandle Pic_Handle; /* Handle used in displaying pictures */
- $$endif Worksheet.Pictures
- RGBColor Saved_ForeColor; /* Place to save colors */
- RGBColor Saved_BackColor; /* Place to save colors */
- RGBColor DrawingColor; /* Place to make colors */
- $Worksheet.name$RecPtr theWS;
-
-
- LocateInstance(whichWindow);
-
- if (RecPtr_$Worksheet.name$ != nil) /* Only do if the window is us */
- {
- theWS = RecPtr_$Worksheet.name$;
-
- GetPort(&SavePort); /* Save the current port */
- SetPort(whichWindow); /* Set the port to my window */
-
- $$if Worksheet.HasControls
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- GetForeColor(&Saved_ForeColor); /* Save the fore color */
- GetBackColor(&Saved_BackColor); /* Save the back color */
-
- RGBForeColor(&Black_ForeColor); /* Set the fore color to Black */
- RGBBackColor(&White_BackColor); /* Set the back color to White */
- } /* End of IF */
-
-
- $$Set TextSize = 12
- $$Set TextFont = applFont
- $$Set TextStyle = 0
- $$Loop Control.type = StaticText
- /* Draw static text, $Control.FullName$ */
- $$if Control.TextColor ! Black
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- DrawingColor.red = 0x$Control.RedTextColor$;
- DrawingColor.green = 0x$Control.GreenTextColor$;
- DrawingColor.blue = 0x$Control.BlueTextColor$;
- RGBForeColor(&DrawingColor); /* Set the fore color */
- RGBBackColor(&Saved_BackColor); /* Set the back color */
- }
- $$endif Control.TextColor
- $$if Control.MultipleLine
- SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
- DrawStaticTextBox(sResC_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
- $$endif Control.MultipleLine
- $$if Control.SingleLine
- DrawStaticLine(sResC_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
- $$endif Control.SingleLine
- $$if Control.TextColor ! Black
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- RGBForeColor(&Black_ForeColor); /* Set the fore color */
- RGBBackColor(&White_BackColor); /* Set the back color */
- }
- $$endif Control.TextColor
-
- $$EndLoop
- $$Loop Control.type = Icon
- $$if Control.Graphic
- /* Draw an Icon */
- Icon_Handle = GetIcon(ResC_N_$Control.name$); /* Get Icon into memory */
- SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
- if (Icon_Handle != nil) /* Only use handle if it is valid */
- PlotIcon(&tempRect,Icon_Handle); /* Draw the icon in the window */
-
- $$endif Control.Graphic
- $$EndLoop
- $$Loop Control.type = Sicn
- $$if Control.Graphic
- /* Draw an sicn */
- SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
- Plot_Sicn(ResC_N_$Control.name$, &tempRect); /* Draw the sicn */
-
- $$endif Control.Graphic
- $$EndLoop
- $$Loop Control.type = Picture
- $$if Control.Graphic
- /* Draw the Picture */
- Pic_Handle = GetPicture(ResC_N_$Control.name$); /* Get Picture into memory */
- SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
- $$if Control.ClipPicture
- if (Pic_Handle != nil) /* Only use handle if it is valid */
- {
- ClipRect(&tempRect); /* Clip picture to this rectangle */
- HLock((Handle)Pic_Handle); /* Lock the handle before using it */
- tempRect.right = tempRect.left + ((*Pic_Handle)->picFrame.right - (*Pic_Handle)->picFrame.left);
- tempRect.bottom = tempRect.top + ((*Pic_Handle)->picFrame.bottom - (*Pic_Handle)->picFrame.top);
- HUnlock((Handle)Pic_Handle); /* Unlock the picture again */
- }
- $$endif Control.ClipPicture
- if (Pic_Handle != nil) /* Only use handle if it is valid */
- DrawPicture(Pic_Handle, &tempRect); /* Draw this picture */
- $$if Control.ClipPicture
- SetRect(&tempRect, 0, 0, 32000, 32000); /* Widen the clip area again */
- ClipRect(&tempRect); /* Set the clip area */
- $$endif Control.ClipPicture
- $$endif Control.Graphic
-
- $$EndLoop
- $$Loop Control.type = EditText
- /* Draw Edit text */
- $$if Control.TextColor ! Black
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- DrawingColor.red = 0x$Control.RedTextColor$;
- DrawingColor.green = 0x$Control.GreenTextColor$;
- DrawingColor.blue = 0x$Control.BlueTextColor$;
- RGBForeColor(&DrawingColor); /* Set the fore color */
- RGBBackColor(&Saved_BackColor); /* Set the back color */
- }
- $$endif Control.TextColor
- DrawTheTEArea(&theWS->TERect_$Control.name$,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
- $$if Control.TextColor ! Black
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- RGBForeColor(&Black_ForeColor); /* Set the fore color */
- RGBBackColor(&White_BackColor); /* Set the back color */
- }
- $$endif Control.TextColor
-
- $$EndLoop
- $$Loop Control.type = Line
- /* Draw a line, $Control.FullName$ */
- $$if Control.GrayLine
- PenPat(&qd.gray); /* Set the gray pen pattern */
- $$endif Control.GrayLine
- $$if Control.LineWidth ! 1
- PenSize($Control.LineWidth$,$Control.LineWidth$);
- $$endif Control.LineWidth
- MoveTo($Control.LeftPosition$,$Control.TopPosition$); /* Horz,vert, Move to starting position */
- LineTo($Control.RightPosition$,$Control.BottomPosition$); /* Horz,vert, Draw to the ending position */
- $$if Control.LineWidth ! 1
- PenSize(1,1);
- $$endif Control.LineWidth
- $$if Control.GrayLine
- PenPat(&qd.black); /* Back to default pen pattern */
- $$endif Control.GrayLine
-
- $$EndLoop
- $$Loop Control.type = List
- /* Update a List */
- UpdateTheList(theWS->theWindow->visRgn,theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
- $Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
-
- $$EndLoop
-
- if (Has.ColorQD) /* See if color QuickDraw is around */
- {
- RGBForeColor(&Saved_ForeColor); /* Restore the fore color */
- RGBBackColor(&Saved_BackColor); /* Restore the back color */
- } /* End of IF */
-
- $$endif Worksheet.HasControls
-
- TextFont(applFont); /* Back to the application font */
- TextSize(12); /* Back to the application size */
- TextFace(0); /* Set text style */
-
- U_Update$Worksheet.name$(theWS); /* Call the user window update routine */
-
- $$if Worksheet.Document
- DrawGrowIcon(theWS->theWindow); /* Draw the Grow box */
-
- $$endif Worksheet.Document
- SetPort(SavePort); /* Restore the old port */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: Open_$Worksheet.name$ */
- /* Purpose: Open our window */
-
- void Open_$Worksheet.name$(void)
- {
- $$if Worksheet.Document
- Rect temp2Rect; /* Used for scrollbar placement */
- short ScrollAreaHeight; /* Used for scrollbar placement */
- short ScrollAreaWidth; /* Used for scrollbar placement */
- $$endif
- WindowPtr BehindWindow; /* Used for window placement */
- long theLong; /* Used for icons and hotspots definition */
- $$if Worksheet.SavePosition
- Point DefaultPosition; /* Used for window placement */
- $$endif
- $Worksheet.name$RecPtr theWS;
-
-
- if ((ListRecPtr_$Worksheet.name$ == nil) || (MultipleAllowed_$Worksheet.name$))
- {
- theWS = ($Worksheet.name$RecPtr)NewPtrClear(sizeof($Worksheet.name$Rec));
- RecPtr_$Worksheet.name$ = theWS;
- theWS->Next = ListRecPtr_$Worksheet.name$;
- ListRecPtr_$Worksheet.name$ = theWS;
-
- InitRecord(theWS);
-
- BehindWindow = Mk_BehindWindow($Worksheet.Layer$); /* Get which window to place below */
-
- if (Has.ColorQD) /* See if color QuickDraw is around */
- theWS->theWindow = GetNewCWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the COLOR window from the resource file */
- else
- theWS->theWindow = GetNewWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the window from the resource file */
- Mk_RegisterWindow(theWS->theWindow,$Worksheet.Layer$); /* Register the window with the layers */
- SetPort(theWS->theWindow); /* Prepare to write into our window */
-
- $$if Worksheet.Center
- tempRect = theWS->theWindow->portRect; /* Get the windows position and size */
- $$if Worksheet.CenterHorz
- tempRect.left = ((screenRect.bounds.right - screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2; /* Center Horz */
- $$endif Worksheet.CenterHorz
- $$if Worksheet.CenterVert
- tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3; /* 1/3 vert */
- if (tempRect.top < 40) /* Keep below the menu bar */
- tempRect.top = 40;
- $$endif Worksheet.CenterVert
- MoveWindow(theWS->theWindow,tempRect.left,tempRect.top,true);
- $$endif
-
- $$Loop Control.type = Button
- /* Make a button */
- theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,theWS->Enable_$Control.name$,0);
-
- $$EndLoop Control.type = Button
- $$Loop Control.type = Checkbox
- /* Make a checkbox */
- theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = Checkbox
- $$Loop Control.type = Radio
- /* Make a Radio */
- theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = Radio
- $$Loop Control.type = HotRect
- /* Make a HotSpot/rect */
- theWS->Ctrl_$Control.name$ = MakeHotSpot(theWS->theWindow,ResC_$Control.name$,
- $Control.MakeHotSpot$,$Control.LineWidth$,$Control.ShadowWidth$,sResC_$Control.name$,theWS->Enable_$Control.name$);
- theWS->Rect_$Control.name$ = (*(theWS->Ctrl_$Control.name$))->contrlRect; /* Get the position */
-
- $$EndLoop Control.type = HotRect
- $$Loop Control.type = List
- /* Make a List */
- Make_A_List(&theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
- theWS->theWindow,ResC_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
-
- $$EndLoop Control.type = List
- $$Loop Control.type = EditText
- /* Open a TE box, $Control.FullName$ */
- Make_TE_Area(&theWS->TE_$Control.name$,&theWS->TERect_$Control.name$,$Control.TextSize$,$Control.TextFont$,sResC_$Control.name$);/* Make the TE */
- TESetText(&theWS->TEStr_$Control.name$[1],theWS->TEStr_$Control.name$[0],theWS->TE_$Control.name$);
-
- $$EndLoop Control.type = EditText
- $$Loop Control.type = Icon
- $$if Control.NonGraphic
- /* Make an icon button */
- theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
-
- $$endif Control.NonGraphic
- $$EndLoop Control.type = Icon
- $$Loop Control.type = Sicn
- $$if Control.NonGraphic
- /* Make an sicn button */
- theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
-
- $$endif Control.NonGraphic
- $$EndLoop Control.type = Sicn
- $$Loop Control.type = Picture
- $$if Control.NonGraphic
- /* Make an picture button */
- theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
- $$if Control.ClipPicture
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,1,0,0); /* Clipped */
- $$endif Control.ClipPicture
- $$if Control.ResizePicture
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,0,0,0); /* Resized */
- $$endif Control.ResizePicture
-
- $$endif Control.NonGraphic
- $$EndLoop Control.type = Picture
- $$Loop Control.type = ScrollBar
- /* Make a scroll bar */
- theWS->Ctrl_$Control.name$ = GetNewControl(ResC_$Control.name$,theWS->theWindow);/* Make a new scrollbar */
- if (theWS->Enable_$Control.name$)
- HiliteControl(theWS->Ctrl_$Control.name$,0); /* Enable the ScrollBar */
- else
- HiliteControl(theWS->Ctrl_$Control.name$,255); /* Disable the ScrollBar */
- MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = ScrollBar
- $$Loop Control.type = Popup
- /* Make a Popup Menu */
- theWS->Ctrl_$Control.name$ = MakePopupMenu(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,mResC_$Control.name$,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = Popup
- $$Loop Control.type = Palette
- /* Make a Palette */
- theWS->Ctrl_$Control.name$ = MakePalette(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,$Control.NumRows$,$Control.NumColumns$,ResC_N_$Control.name$,$Control.HMethod$);
-
- $$EndLoop Control.type = Palette
- $$Loop Control.type = UButton
- /* Make a plugin button */
- theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,0);
-
- $$EndLoop Control.type = UButton
- $$Loop Control.type = UToggle
- /* Make a plugin toggle, $Control.FullName$ */
- theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = UToggle
- $$Loop Control.type = UGauge
- /* Make a plugin gauge, $Control.FullName$ */
- theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
- theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
- MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
-
- $$EndLoop Control.type = UGauge
-
- $$if Worksheet.Document
- $$if Worksheet.ScrollHorz
- SetRect(&tempRect,1,1,1,1);
- theWS->ScrollHHandle = NewControl(theWS->theWindow,&tempRect,"\pHorz Scroll",true,1,1,100,scrollBarProc,12345L);
- Resized_$Worksheet.name$(&tempRect,theWS->theWindow);
- HiliteControl(theWS->ScrollHHandle,255);
- $$endif
- $$if Worksheet.ScrollVert
- SetRect(&tempRect,1,1,1,1);
- theWS->ScrollVHandle = NewControl(theWS->theWindow,&tempRect,"\pVert Scroll",true,1,1,100,scrollBarProc,12346L);
- Resized_$Worksheet.name$(&tempRect,theWS->theWindow);
- HiliteControl(theWS->ScrollVHandle,255);
- $$endif
- $$endif Worksheet.Document
-
- $$if Worksheet.SavePosition
- SetPort(theWS->theWindow); /* Select our window */
- DefaultPosition.h = 0; /* Reset Horz position */
- DefaultPosition.v = 0; /* Reset Vert position */
- LocalToGlobal(&DefaultPosition); /* Get global location */
- PositionWindow(theWS->theWindow,theWindowLocRec.Loc_$Worksheet.name$,DefaultPosition);
-
- $$endif Worksheet.SavePosition
-
- U_Open$Worksheet.name$(theWS); /* Call the users window open routine */
-
- ShowWindow(theWS->theWindow); /* Show the window now */
-
- $$Link Worksheet.Open
- }
- else
- theWS = ListRecPtr_$Worksheet.name$;
-
- Mk_HiliteWindow(theWS->theWindow); /* Already open, so show it */
- }
-
- /* ======================================================= */
-
- /* Routine: Activate_$Worksheet.name$ */
- /* Purpose: We activated or deactivated */
-
- void Activate_$Worksheet.name$(WindowPtr whichWindow,Boolean Do_An_Activate)
- {
- WindowPtr SavePort; /* Place to save the last port */
- $Worksheet.name$RecPtr theWS;
-
-
- LocateInstance(whichWindow);
-
- if (RecPtr_$Worksheet.name$ != nil) /* Only do if the window is us */
- {
- theWS = RecPtr_$Worksheet.name$;
-
- GetPort(&SavePort); /* Save the current port */
- SetPort(whichWindow); /* Set the port to my window */
-
- $$if Worksheet.Document
- DrawGrowIcon(whichWindow); /* Draw the Grow box */
-
- $$endif Worksheet.Document
- if (!Do_An_Activate) /* Handle the deactivate */
- {
- if (theInput != nil) /* See if there is already a TE area */
- TEDeactivate(theInput); /* Yes, so turn it off */
- theInput = nil; /* Deactivate the TE area */
- $$if Worksheet.Document
- $$if Worksheet.ScrollHorz
- HiliteControl(theWS->ScrollHHandle,255);
- $$endif
- $$if Worksheet.ScrollVert
- HiliteControl(theWS->ScrollVHandle,255);
- $$endif
- $$endif Worksheet.Document
- $$Link Worksheet.Deactivate
- }
- else
- {
- $$if Worksheet.Document
- $$if Worksheet.ScrollHorz
- HiliteControl(theWS->ScrollHHandle,0);
- $$endif
- $$if Worksheet.ScrollVert
- HiliteControl(theWS->ScrollVHandle,0);
- $$endif
- $$endif Worksheet.Document
- $$Link Worksheet.Activate
- }
-
- U_Activate$Worksheet.name$(theWS,Do_An_Activate); /* Call the user window activate routine */
-
- SetPort(SavePort); /* Restore the old port */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: Do_A_Button */
- /* Purpose: Handle a button pressed */
-
- static void Do_A_Button($Worksheet.name$RecPtr theWS,ControlHandle theControl) /* Handle a button being pressed */
- {
- long RefCon; /* RefCon for controls */
- short UnHiliteValue; /* For unhilite */
- short theSelection; /* For palettes and popups */
-
-
- if (theWS != nil) /* Only do if the window is us */
- {
-
- HiliteControl(theControl,10); /* Darken the button */
- UnHiliteValue = 0; /* To lighten the button */
- RefCon = GetCRefCon(theControl); /* get control refcon */
-
- switch (RefCon) /* Select correct button */
- {
- $$Loop Control.type = Button
- $$if Control.HasLinks
- case ResC_$Control.name$: /* Button, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif
- $$EndLoop Control.type = Button
- $$Loop Control.type = HotRect
- $$if Control.HasLinks
- $$if Control.HotSpot
- case ResC_$Control.name$: /* HotSpot, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif Control.HotSpot
- $$endif
- $$EndLoop Control.type = HotRect
- $$Loop Control.type = Icon
- $$if Control.HasLinks
- $$if Control.NonGraphic
- case ResC_$Control.name$: /* Icon, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif Control.NonGraphic
- $$endif
- $$EndLoop Control.type = Icon
- $$Loop Control.type = Sicn
- $$if Control.HasLinks
- $$if Control.NonGraphic
- case ResC_$Control.name$: /* Sicn, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif Control.NonGraphic
- $$endif
- $$EndLoop Control.type = Sicn
- $$Loop Control.type = Picture
- $$if Control.HasLinks
- $$if Control.NonGraphic
- case ResC_$Control.name$: /* Picture, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif Control.NonGraphic
- $$endif
- $$EndLoop Control.type = Picture
- $$Loop Control.type = UButton
- $$if Control.HasLinks
- case ResC_$Control.name$: /* Plugin Button, $Control.FullName$ */
- $$Link Control.Select
- break;
- $$endif
- $$EndLoop Control.type = UButton
- $$Loop Control.type = Popup
- case ResC_$Control.name$: /* PopUp, $Control.FullName$ */
- theSelection = GetCtlValue(theWS->Ctrl_$Control.name$); /* Get the Popup selection value */
- switch (theSelection) /* Select correct item */
- {
- $$Loop PopupItems
- case $Control.PopupID$: /* $Control.PopupID$, for $Control.PopupName$ */
- break;
- $$EndLoop PopupItems
-
- default: /* allow other buttons, trap for debug */
- break; /* end of otherwise */
- } /* end of switch */
- break;
- $$EndLoop Control.type = Popup
- $$Loop Control.type = Palette
- case ResC_$Control.name$: /* Tool palette, $Control.FullName$ */
- theWS->Value_$Control.name$ = GetCtlValue(theWS->Ctrl_$Control.name$);/* Get the palette value, 0xrrcc, rr is row, cc is column */
- break;
- $$EndLoop Control.type = Palette
-
- default: /* allow other buttons, trap for debug */
- break; /* end of otherwise */
- } /* end of switch */
-
- U_DoButton$Worksheet.name$(theWS,RefCon,theControl,&UnHiliteValue);/* Call to handle any extra user buttons */
-
- HiliteControl(theControl,UnHiliteValue); /* Lighten the button */
- }
-
- } /* End of Handle a button being pressed */
-
- $$if Worksheet.CheckboxesOrRadios
- /* ======================================================= */
-
- static void Do_A_Checkbox($Worksheet.name$RecPtr theWS,ControlHandle theControl)/* Handle a checkbox being pressed */
- {
- long RefCon; /* RefCon for controls */
- short theValue; /* Current value of a control */
-
-
- if (theWS != nil)
- {
- RefCon = GetCRefCon(theControl); /* get control refcon */
- theValue = GetCtlValue(theControl); /* Get current value */
- theValue = (theValue + 1) & 1; /* Change value from 1 to 0 or from 0 to 1 */
-
- U_DoCheckbox$Worksheet.name$(theWS,theControl,&theValue); /* Call user routine, allow changing value */
-
- switch (RefCon) /* Select correct control */
- {
- $$Loop Control.type = Checkbox
- case ResC_$Control.name$: /* Checkbox, $Control.FullName$ */
- SetCtlValue(theControl, theValue); /* Set checkbox to new value */
- theWS->Value_$Control.name$ = theValue;
- $$if Control.HasLinks
- if (theValue == 0)
- {
- $$Link Control.Deselect
- }
- else
- {
- $$Link Control.Select
- }
- $$endif
- break;
- $$EndLoop Control.type = Checkbox
- $$Loop Control.type = UToggle
- case ResC_$Control.name$: /* Plugin Toggle, $Control.FullName$ */
- SetCtlValue(theControl, theValue); /* Set checkbox to new value */
- theWS->Value_$Control.name$ = theValue;
- $$if Control.HasLinks
- if (theValue == 0)
- {
- $$Link Control.Deselect
- }
- else
- {
- $$Link Control.Select
- }
- $$endif
- break;
- $$EndLoop Control.type = UToggle
- $$Loop Control.type = Radio
- case ResC_$Control.name$: /* Radio, $Control.FullName$ */
- theWS->Value_$Control.name$ = 1; /* Set the Radio value */
- SetCtlValue(theControl,1); /* Select this Radio */
-
- /* Clear other Radio values in this group */
- $$Loop RadioGroup
- SetCtlValue(theWS->Ctrl_$Control.name$,0);
- theWS->Value_$Control.name$ = 0; /* Clear other radio */
- $$EndLoop RadioGroup
- $$Link Control.Select
- break;
- $$EndLoop Control.type = Radio
-
- default: /* allow other checkboxes and radios, trap for debug */
- break; /* end of otherwise */
- } /* end of case */
- }
-
- }
-
- $$endif
- /* ======================================================= */
-
- /* Routine: Do_$Worksheet.name$ */
- /* Purpose: Handle action to our window, like controls */
-
- void Do_$Worksheet.name$(EventRecord *myEvent)
- {
- short code; /* Location of event in window or controls */
- WindowPtr whichWindow; /* Window pointer where event happened */
- Point myPt; /* Point where event happened */
- ControlHandle theControl; /* Handle for a control */
- $Worksheet.name$RecPtr theWS;
-
-
- theWS = nil;
-
- code = FindWindow(myEvent->where,&whichWindow); /* Get where in window and which window */
-
- LocateInstance(whichWindow);
-
- if (RecPtr_$Worksheet.name$ != nil) /* Only do if the window is us */
- {
- theWS = RecPtr_$Worksheet.name$;
-
- U_DoEvent$Worksheet.name$(theWS,myEvent);
-
- $$if HasEditLists
- if (myEvent->what == mouseDown)
- {
- myPt = myEvent->where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- $$Loop Control.type = EditText
- if (PtInRect(myPt,&theWS->TERect_$Control.name$)) /* Check for pressed in the TE Edit Text */
- {
- Activate_TE_Area(false,myPt,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
- whichWindow = NIL; /* Do not let anyone else handle it */
- }
-
- $$EndLoop Control.type = EditText
- $$Loop Control.type = List
- if (PtInRect(myPt,&theWS->ListRect_$Control.name$))
- {
- ClickInTheList(myPt,myEvent->modifiers,theWS->List_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
- whichWindow = NIL; /* Do not let anyone else handle it */
- }
-
- $$EndLoop Control.type = List
- }
-
- $$endif HasEditLists
- if ((theWS->theWindow == whichWindow) && (code == inContent)) /* for our window */
- {
- myPt = myEvent->where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- code = FindControl(myPt,whichWindow,&theControl); /* Get type of control */
-
- $$if Worksheet.Scrollbars
- if ((code == inUpButton) || (code == inDownButton) || (code == inThumb) || (code == inPageDown) || (code == inPageUp))
- Do_A_ScrollBar(theWS,code,theControl,myPt);/* Do scrollbars */
- else
- $$endif
- if (code != 0) /* Check type of control */
- code = TrackControl(theControl,myPt,(ControlActionUPP)-1);/* Track the control */
- if (code == inButton)
- Do_A_Button(theWS,theControl); /* Do buttons */
- $$if Worksheet.CheckboxesOrRadios
- else if (code == inCheckBox)
- Do_A_Checkbox(theWS,theControl); /* Do checkboxes and radios */
- $$endif
-
- }
- }
- }
-
- /* ======================================================= */
- /* ======================================================= */
- $$CloseFile
- $$EndLoop
-
-
-