home *** CD-ROM | disk | FTP | other *** search
- /* ===================================
-
- File: Source_1.c
- Function: Handle all operations for this window
- History: 4/27/89 Original by Prototyper.
-
- ================================= */
-
- #include "Source_1.h"
- #include "pix_io.h"
- #include <ColorToolbox.h>
- #include <IM5protos.h>
-
- extern RGBColor BlackRGB, whiteRGB, grayRGB;
- extern short pix_zoom;
- extern short src_changed; /* 1 if pict scrolled or changed, 0 otherwise */
-
- CGrafPtr proton_bmap; /* off-screen bitmap of proton image */
- PicHandle proton_pic; /* handle to PICT for source 1 */
- Rect proton_rect; /* size of offscreen pict */
- WindowPtr proton_Window; /* Window pointer -- global variable */
-
- short s1_off_top, s1_off_left; /* offsets on the window from scrolling */
- static Str255 filename; /* local - image file, if any, associated with this window */
-
- static void draw_proton( void );
-
- static void HandleVScrollBar (short code, short Start, short Stop,
- short Increment, short LIncrement,
- ControlHandle theControl, Point myPt);
-
- static void HandleHScrollBar (short code, short Start, short Stop,
- short Increment, short LIncrement,
- ControlHandle theControl, Point myPt);
-
- static void Do_A_ScrollBar (short code, ControlHandle theControl, Point myPt);
-
-
-
- /* *********************************** */
- /* These are the other includes for general routines */
-
- #include <Strings.h>
- extern char *strcpy (Str255 *, char *); /* LSC string prototype */
-
- /* *********************************** */
-
- #define TRUE 1
- #define FALSE 0
- #define NIL 0
-
- /* *********************************** */
-
-
-
-
- /* Scrollbar ID */
- #define I_Vert_Scroll_bar 25
- /* Scrollbar ID */
- #define I_Horiz_Scroll_bar 24
-
- static ControlHandle CtrlHandle; /* Control handle */
- static ControlHandle ScrollHHandle, ScrollVHandle; /* Scrolling Control*/
- static Str255 sTemp; /* Get text entered, temp holding */
- static OSErr MyErr; /* General OS error return */
- static ControlHandle C_Vert_Scroll_bar; /* Scroll bar Control Handle */
- static ControlHandle C_Horiz_Scroll_bar; /* Scroll bar Control Handl*/
-
- /* ====================================== */
-
- /* Initialize us so all our routines can be activated */
- void Init_proton ()
- {
- proton_Window = NIL; /* Make sure other routines know we are not */
- proton_rect.top = 0;
- proton_rect.bottom = all_my_colors;
- proton_rect.left = 0;
- proton_rect.right = 300;
- }
-
- /* ================================= */
-
- void activate_proton (whichWindow, modifiers)
- WindowPtr whichWindow;
- long modifiers;
- {
- WindowPtr SavePort;
-
- GetPort (&SavePort);
- if ( modifiers & activeFlag != 0 )
- {
- SelectWindow(whichWindow);
- SetPort(whichWindow);
- ShowControl (ScrollHHandle);
- ShowControl (ScrollVHandle);
- DrawGrowIcon( whichWindow );
- DrawControls( whichWindow );
- }
- else
- {
- SetPort(whichWindow);
- HideControl (ScrollHHandle);
- HideControl (ScrollVHandle);
- DrawGrowIcon( whichWindow );
- DrawControls( whichWindow );
- }
- SetPort(SavePort);
- }
-
- typedef WStateData **WStateHandle;
-
- void zoom_proton( where, whichWindow, code )
- Point *where;
- WindowPeek whichWindow;
- short code;
- {
- Point myPt;
- WStateHandle WState;
-
- SetPort (whichWindow);
-
- if ( whichWindow->dataHandle != NIL )
- {
- WState = (WStateHandle) whichWindow->dataHandle;
- (**WState).stdState = proton_rect;
- (**WState).stdState.top += 40;
- (**WState).stdState.left += 2;
- (**WState).stdState.right += 2;
- (**WState).stdState.bottom += 40;
- }
- myPt = *where; /* Get mouse position */
- GlobalToLocal (&myPt); /* Make it relative */
-
- if (TrackBox (whichWindow, myPt, code) == TRUE)
- {
- EraseRect( &whichWindow->port.portRect );
- ZoomWindow (whichWindow, code, TRUE);
- InvalRect (&whichWindow->port.portRect);
- }
- Resized_proton (proton_Window);
- }
-
- void grow_proton( where, whichWindow )
- Point *where;
- WindowPtr whichWindow;
- {
- Point myPt;
- long mResult;
-
- SetPort (whichWindow);
-
- myPt = *where; /* Get mouse position */
- GlobalToLocal (&myPt); /* Make it relative */
-
- mResult = GrowWindow (whichWindow, *where, &proton_rect);
-
- SizeWindow (whichWindow, LoWord (mResult),
- HiWord (mResult), TRUE);
- Resized_proton (proton_Window);
- }
-
- /* We were resized or zoomed, update the scrolling scrollbars */
- void Resized_proton (whichWindow)/* Resized this window */
- WindowPtr whichWindow; /* Window that was resized */
- {
- WindowPtr SavePort; /* Place to save the last port */
-
- GetPort (&SavePort);
- SetPort (proton_Window);
-
- if (ScrollHHandle != NIL)
- {
- HLock ((Handle)ScrollHHandle);
- HideControl (ScrollHHandle);
-
- InvalRect (&(*ScrollHHandle)->contrlRect); /* Flag old position for update rout*/
-
- MoveControl (ScrollHHandle, proton_Window->portRect.left-1,
- proton_Window->portRect.bottom - 15);
- SizeControl (ScrollHHandle, (proton_Window->portRect.right
- - proton_Window->portRect.left) - 13, 16);
-
- ShowControl (ScrollHHandle);
- HUnlock ((Handle)ScrollHHandle);
- }
- if (ScrollVHandle != NIL)
- {
- HLock ((Handle)ScrollVHandle);
- HideControl (ScrollVHandle);
-
- InvalRect (&(*ScrollVHandle)->contrlRect); /* Flag old position for update rout*/
-
- MoveControl (ScrollVHandle, proton_Window->portRect.right-15,
- proton_Window->portRect.top-1);
- SizeControl (ScrollVHandle, 16, (proton_Window->portRect.bottom
- - proton_Window->portRect.top) - 13);
-
- ShowControl (ScrollVHandle);
- HUnlock ((Handle)ScrollVHandle);
- }
- InvalRect(&proton_Window->portRect);
- DrawGrowIcon (proton_Window);
- SetPort (SavePort);
- }
- /* End of function */
-
- /* ====================================== */
-
- /* Update our window, someone uncovered a part of us */
- void UpDate_proton (whichWindow)
- WindowPtr whichWindow;
- {
- WindowPtr SavePort; /* Place to save the last port */
-
- GetPort (&SavePort); /* Save the current port */
- SetPort (proton_Window); /* Set the port to my window */
-
- InvalRect(&proton_Window->portRect);
-
- BeginUpdate( proton_Window );
- draw_proton();
- DrawControls (proton_Window); /* Draw all the controls */
- DrawGrowIcon (proton_Window); /* Draw the Grow box */
- EndUpdate(proton_Window);
- SetPort (SavePort); /* Restore the old port */
- }
-
- static void draw_proton()
- {
- Rect clipper;
- Rect offrect; /* coords in offscreen bitmap */
- short i;
-
- clipper.top = proton_Window->portRect.top;
- clipper.bottom = proton_Window->portRect.bottom - 15;
- clipper.right = proton_Window->portRect.right - 15;
- clipper.left = proton_Window->portRect.left;
-
- ClipRect( &clipper );
-
- EraseRect( &clipper );
- if ( s1_off_top < proton_rect.bottom &&
- s1_off_left < proton_rect.right )
- {
- if ( proton_bmap != NIL )
- {
- offrect = clipper;
- offrect.top += s1_off_top;
- offrect.bottom += s1_off_top;
- if ( offrect.bottom > proton_rect.bottom + s1_off_top )
- {
- offrect.bottom = proton_rect.bottom;
- clipper.bottom = proton_rect.bottom - s1_off_top;
- }
- offrect.left += s1_off_left;
- offrect.right += s1_off_left;
- if ( offrect.right > proton_rect.right + s1_off_left )
- {
- offrect.right = proton_rect.right;
- clipper.right = proton_rect.right - s1_off_left;
- }
-
- HLock((Handle) (proton_bmap->portPixMap));
- CopyBits( *(proton_bmap->portPixMap), &thePort->portBits,
- &offrect, &clipper, (short) srcCopy,
- (RgnHandle) NIL);
- HUnlock((Handle) (proton_bmap->portPixMap));
- }
- else
- {
- SetOrigin( s1_off_left, s1_off_top );
- for ( i = 0; i < all_my_colors; i++)
- {
- PmForeColor( i );
- MoveTo( 0, i );
- LineTo( 300, i );
- }
- SetOrigin( 0, 0);
- }
- }
- ClipRect( &proton_Window->portRect );
- }
-
- /* End of UpDate */
-
- /* =========================================== */
- /* vertical scroll bar */
-
- static void HandleVScrollBar (code, Start, Stop, Increment, LIncrement,
- theControl, myPt)
- short code; /* Selection code for part of scroll bar */
- short Start; /* Minimum value the scroll bar can assume */
- short Stop; /* Maximum value the scroll bar can assume */
- short LIncrement, Increment; /* Increment to move when pressed in an*/
- ControlHandle theControl; /* Handle to the scroll bar control */
- Point myPt; /* Returned point from track the scrollbar */
- { /* Start of this function */
- short theValue; /* Value of the scrollbar */
- long MaxTick; /* Timer used for repeat scrolling */
-
- do /* Do the scroll as long as the button is do*/
- { /* Timer used for repeat scrolling */
- HiliteControl (theControl, code); /* Darken the arrow */
- theValue = GetCtlValue (theControl); /* Get current state */
-
- if (code == inUpButton) /* See if in the Up arrow */
- {
- theValue = theValue - Increment; /* Subtract the single d*/
- if (theValue < Start) /* Check for boundary conditions */
- theValue = Start; /* Pin at the start value */
- }
-
- if (code == inDownButton) /* See if in the Down arrow */
- {
- theValue = theValue + Increment; /* Add the single decrem*/
- if (theValue > Stop) /* Check for boundary conditions */
- theValue = Stop; /* Pin at the stop value */
- }
-
- if (code == inPageUp) /* See if in the up/left grey area */
- {
- theValue = theValue - LIncrement; /* Subtract the page inc*/
- if (theValue < Start) /* Check for boundary conditions */
- theValue = Start; /* Pin at the Start value */
- }
-
- if (code == inPageDown) /* See if in the down/right grey area */
- {
- theValue = theValue + LIncrement; /* Add the page incremen*/
- if (theValue > Stop) /* Check for boundary conditions */
- theValue = Stop; /* Pin at the Stop value */
- }
-
- if (code == inThumb) /* See if in the drag box area */
- {
- code = TrackControl (theControl, myPt, NIL); /* Let the O*/
- theValue = GetCtlValue (theControl); /* Get current state*/
- }
-
- SetCtlValue (theControl, theValue); /* Set new state */
-
- s1_off_top = (short) ( (double) (proton_rect.bottom - proton_rect.top)
- * (double) theValue / (double) (Stop - Start) );
-
- draw_proton();
-
- MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
- do /* Start of delay routine */
- { /* Spin on doing nothing */
- } while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
-
- HiliteControl (theControl, 0); /* Lighten the arrow */
- } /* End for StillDown */
- while (StillDown () == TRUE); /* End for StillDown */
- }
-
- /* End for HandleVScrollBar */
-
- /* ====================================================== */
-
- /* horizontal scroll bar */
-
- static void HandleHScrollBar (code, Start, Stop, Increment, LIncrement,
- theControl, myPt)
- short code; /* Selection code for part of scroll bar */
- short Start; /* Minimum value the scroll bar can assume */
- short Stop; /* Maximum value the scroll bar can assume */
- short LIncrement, Increment; /* Increment to move when pressed in an*/
- ControlHandle theControl; /* Handle to the scroll bar control */
- Point myPt; /* Returned point from track the scrollbar */
- { /* Start of this function */
- short theValue; /* Value of the scrollbar */
- long MaxTick; /* Timer used for repeat scrolling */
-
- do /* Do the scroll as long as the button is do*/
- { /* Timer used for repeat scrolling */
- HiliteControl (theControl, code); /* Darken the arrow */
- theValue = GetCtlValue (theControl); /* Get current state */
-
- if (code == inUpButton) /* See if in the Up arrow */
- {
- theValue = theValue - Increment; /* Subtract the single d*/
- if (theValue < Start) /* Check for boundary conditions */
- theValue = Start; /* Pin at the start value */
- }
-
- if (code == inDownButton) /* See if in the Down arrow */
- {
- theValue = theValue + Increment; /* Add the single decrem*/
- if (theValue > Stop) /* Check for boundary conditions */
- theValue = Stop; /* Pin at the stop value */
- }
-
- if (code == inPageUp) /* See if in the up/left grey area */
- {
- theValue = theValue - LIncrement; /* Subtract the page inc*/
- if (theValue < Start) /* Check for boundary conditions */
- theValue = Start; /* Pin at the Start value */
- }
-
- if (code == inPageDown) /* See if in the down/right grey area */
- {
- theValue = theValue + LIncrement; /* Add the page incremen*/
- if (theValue > Stop) /* Check for boundary conditions */
- theValue = Stop; /* Pin at the Stop value */
- }
-
- if (code == inThumb) /* See if in the drag box area */
- {
- code = TrackControl (theControl, myPt, NIL); /* Let the O*/
- theValue = GetCtlValue (theControl); /* Get current state*/
- }
-
- SetCtlValue (theControl, theValue); /* Set new state */
-
- s1_off_left = (short) ( (double)(proton_rect.right - proton_rect.left)
- * (double) theValue / (double) (Stop - Start) );
-
- draw_proton();
-
- MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
- do /* Start of delay routine */
- { /* Spin on doing nothing */
- } while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
-
- HiliteControl (theControl, 0); /* Lighten the arrow */
- } /* End for StillDown */
- while (StillDown () == TRUE); /* End for StillDown */
- }
-
- /* End for HandleHScrollBar */
-
- static void Do_A_ScrollBar (code, theControl, myPt) /* Handle a ScrollBa*/
- short code; /* Which place in scrollbar was pressed */
- ControlHandle theControl; /* Which place in scrollbar was pressed */
- Point myPt; /* Where the scrollbar was pressed */
- { /* Start of a ScrollBar being pressed */
- short RefCon;
-
- RefCon = GetCRefCon (theControl); /* get control refcon */
-
- switch (RefCon)
- {
- case I_Vert_Scroll_bar:
- HandleVScrollBar (code, 1, 100, 1, 10, theControl, myPt);
- src_changed = TRUE;
- break;
-
- case I_Horiz_Scroll_bar:
- HandleHScrollBar (code, 1, 100, 1, 10, theControl, myPt);
- src_changed = TRUE;
- break;
-
- default:
- break;
- }
- }
-
- /* Handle a ScrollBar being pressed */
-
- /* ================================= */
-
- /* Open our window and draw everything */
- void Open_proton ()
- {
- Rect tempRect;
-
- if (proton_Window == NIL) /* Handle an open when already opened */
- {
- /* proton_Window = (WindowPtr) GetNewCWindow (8, NIL, (WindowPtr) - 1); -- Get the w*/
-
- tempRect.top = 139;
- tempRect.bottom = 334;
- tempRect.left = 3;
- tempRect.right = 194;
- proton_Window = (WindowPtr) NewCWindow( (Ptr) NIL, &tempRect, "\pProton",
- (Boolean) true, 8, (WindowPtr)-1, (Boolean)false, 8L);
-
- /* MoveWindow (proton_Window, tempRect.left, tempRect.top, TRUE); */
-
- SetPort (proton_Window);
-
- /* Make a scroll bar, Vert Scroll bar */
- ScrollVHandle = GetNewControl (I_Vert_Scroll_bar, proton_Window);
-
- /* Make a scroll bar, Horiz Scroll bar */
-
- ScrollHHandle = GetNewControl (I_Horiz_Scroll_bar, proton_Window);
-
- ShowWindow (proton_Window);
- SelectWindow (proton_Window);
-
- /* NSetPalette( proton_Window, mypalette, pmFgUpdates); */
- /* RGBBackColor(&whiteRGB); */
- /* RGBForeColor(&BlackRGB); /* copybits usually expect black fore and white back */
- /* OpColor(&grayRGB); */
-
- Resized_proton (proton_Window);
- } /* End for if (proton_Window<>nil) */
- else
- {
- SelectWindow (proton_Window); /* Already open, so show it */
- }
- }
-
- /* End of open function */
-
- /* ================================= */
-
- /* Handle action to our window, like controls */
- void Do_proton (myEvent)
- EventRecord *myEvent;
- {
- short RefCon; /* RefCon for controls */
- short code; /* Location of event in window or controls */
- short theValue; /* Current value of a control */
- WindowPtr whichWindow; /* Window pointer where event happened */
- Point myPt; /* Point where event happened */
- ControlHandle theControl; /* Handle for a control */
- WindowPtr SavePort;
-
- /* Start of Window handler */
- if (proton_Window != NIL) /* Handle only when the window is valid */
- {
- GetPort (&SavePort);
- SetPort(proton_Window);
-
- SetOrigin(0, 0);
-
- code = FindWindow (myEvent->where, &whichWindow); /* Get where*/
-
- if ((myEvent->what == mouseDown) && (proton_Window == whichWindow))
- {
- myPt = myEvent->where; /* Get mouse position */
- GlobalToLocal (&myPt); /* Make it relative */
- }
-
- if ((proton_Window == whichWindow) && (code == inContent)) /* for o*/
- {
-
- code = FindControl (myPt, whichWindow, &theControl); /* G*/
-
- if ((code == inUpButton) || (code == inDownButton)
- || (code == inThumb) || (code == inPageDown)
- || (code == inPageUp))
- Do_A_ScrollBar (code, theControl, myPt); /* Do scroll*/
- if (code != 0) /* Check type of control */
- code = TrackControl (theControl, myPt, NIL); /* Track*/
-
- } /* End for if (proton_Window==whichWindow) */
- } /* End for if (proton_Window != NIL) */
- SetPort(SavePort);
- }
-
- /* End of function */
-
- /* ================================= */
-
- void read_proton()
- /* reads a PICT file and displays it in proton window */
- {
- short width, height;
- /*
- put up open-file dialog
- if not cancelled then
- clear out current proton picture
- open selected file
- skip header 512 bytes
- read to find out how big the picture is going to be, and then rewind a bit
- allocate appropriate handle
- read file into the handle
- use the pict Frame in determining how big to create the pixmap for source1
- create pixmap
- copy the PICT into the pixmap
- end if
- */
- GDHandle theMaxDevice;
- Point place;
- Point tempP;
- Rect globRect;
- SFReply theReply;
- SFTypeList theList;
- short ix, iy;
-
- place.h = 60;
- place.v = 60;
- theList[0] = 'PICT';
-
- SFGetFile ( place, "\pOpen a GrayScale PICT file", NIL, 1, theList, NIL, &theReply );
-
- SetPort( proton_Window );
-
- if ( theReply.good != 0 )
- {
- if ( proton_pic != NIL )
- {
- DisposHandle( (Handle) proton_pic );
- }
- if ( GetPic( theReply, &proton_pic ) )
- {
- proton_rect = (**proton_pic).picFrame;
- /* copy that PICT to our pixmap, converting it to use the Flourine colors */
-
- height = proton_rect.bottom - proton_rect.top;
- width = proton_rect.right - proton_rect.left;
- proton_rect.top = 0;
- proton_rect.bottom = height;
- proton_rect.left = 0;
- proton_rect.right = width;
-
- tempP.v = proton_Window->portRect.top;
- tempP.h = proton_Window->portRect.left;
- LocalToGlobal(&tempP);
- globRect.top = tempP.v;
- globRect.left = tempP.h;
-
- tempP.v = proton_Window->portRect.bottom;
- tempP.h = proton_Window->portRect.right;
- LocalToGlobal(&tempP);
- globRect.bottom = tempP.v;
- globRect.right = tempP.h;
-
- theMaxDevice = GetMaxDevice(&globRect); /*get the maxDevice*/
-
- proton_bmap = pic_to_bmap( proton_pic, &proton_rect, theMaxDevice );
-
- if ( proton_bmap != NIL )
- {
- DisposHandle( (Handle) proton_pic );
- }
- src_changed = TRUE;
- }
- else /* failed to get a pict */
- {
- clear_proton();
- }
- }
- UpDate_proton (proton_Window);
- }
-
- void paste_proton() /* !!! change this to use off screen bitmap */
- /* paste a PICT from the clipboard and displays it in proton window */
- {
- long length, offset;
- long width, height, size;
- /*
- look for PICT resource in clipboard
- if there is a PICT then
- clear out current proton picture
- read to find out how big the picture is going to be, and then rewind a bit
- allocate appropriate handle
- read paste into the handle
- use the pict Frame in determining how big to create the pixmap for source1
- create pixmap
- copy the PICT into the pixmap
- end if
- */
- proton_pic = (PicHandle) NewHandle(0);
- length = GetScrap( (Handle) proton_pic, 'PICT', &offset);
- if ( length > 0 )
- {
- proton_rect = (**proton_pic).picFrame;
- width = proton_rect.right - proton_rect.left;
- height = proton_rect.bottom - proton_rect.top;
- size = width * height;
- /* allocate offscreen-buffer based on size, etc.*/
- proton_rect.top = 0;
- proton_rect.left = 0;
- proton_rect.bottom = height;
- proton_rect.right = width;
- }
- UpDate_proton (proton_Window);
- }
-
- void clear_proton() /* !!! change this to use off screen bit map */
- /* "cut" without clipboard */
- {
- if (proton_pic != NIL )
- {
- DisposHandle( (Handle) proton_pic );
- }
- proton_rect.top = 0;
- proton_rect.bottom = all_my_colors;
- proton_rect.left = 0;
- proton_rect.right = 300;
- UpDate_proton (proton_Window);
- }
-
- void crop_proton()
- {
-
- }
-