home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
-
- mini.windows.c
-
- window functions for MiniEdit
-
- *********************************************************************/
-
- /*
-
- #include <QuickDraw.h>
- #include <MacTypes.h>
- #include <WindowMgr.h>
- #include <TextEdit.h>
- #include <ControlMgr.h>
- #include <EventMgr.h>
-
- */
-
- #include "MiniEdit.h"
-
- extern WindowRecord wRecord;
- extern WindowPtr myWindow;
- extern ControlHandle vScroll;
- extern TEHandle TEH;
- extern int linesInFolder;
-
- static pascal Boolean ClickLoopProc(void);
- static pascal Boolean WordBreakProc(char *text, int charPos);
-
- SetUpWindows()
- {
- Rect destRect, viewRect;
- FontInfo myInfo;
- int height;
- Rect vScrollRect;
-
-
- SetPort((myWindow = GetNewWindow( windowID, &wRecord, (WindowPtr) -1L )));
- TextFont(4);
- TextSize(9);
- vScrollRect = (*myWindow).portRect;
- vScrollRect.left = vScrollRect.right-15;
- vScrollRect.right += 1;
- vScrollRect.bottom -= 14;
- vScrollRect.top -= 1;
- vScroll = NewControl( myWindow, &vScrollRect, "\p", 1, 0, 0, 0,
- scrollBarProc, 0L);
-
- viewRect = myWindow->portRect; /* thePort->portRect; */
- viewRect.right -= SBarWidth;
- viewRect.bottom -= SBarWidth;
- InsetRect(&viewRect, 4, 4);
- TEH = TENew( &viewRect, &viewRect );
-
- SetWordBreak(WordBreakProc, TEH);
- SetClikLoop(ClickLoopProc, TEH);
-
- SetView(myWindow);
- }
-
- AdjustText ()
-
- {
- int oldScroll, newScroll, delta;
-
- oldScroll = (**TEH).viewRect.top - (**TEH).destRect.top;
- newScroll = GetCtlValue(vScroll) * (**TEH).lineHeight;
- delta = oldScroll - newScroll;
- if (delta != 0)
- TEScroll(0, delta, TEH);
- }
-
-
- SetVScroll()
- {
- register int n;
-
- n = (**TEH).nLines-linesInFolder;
-
- if ((**TEH).teLength > 0 && (*((**TEH).hText))[(**TEH).teLength-1]=='\r')
- n++;
-
- SetCtlMax(vScroll, n > 0 ? n : 0);
- }
-
- ShowSelect()
-
- {
- register int topLine, bottomLine, theLine;
-
- SetVScroll();
- AdjustText();
-
- topLine = GetCtlValue(vScroll);
- bottomLine = topLine + linesInFolder;
-
- if ((**TEH).selStart < (**TEH).lineStarts[topLine] ||
- (**TEH).selStart >= (**TEH).lineStarts[bottomLine]) {
- for (theLine = 0; (**TEH).selStart >= (**TEH).lineStarts[theLine]; theLine++)
- ;
- SetCtlValue(vScroll, theLine - linesInFolder / 2);
- AdjustText();
- }
- }
-
- SetView(w)
- WindowPtr w;
- {
- (**TEH).viewRect = w->portRect;
- (**TEH).viewRect.right -= SBarWidth;
- (**TEH).viewRect.bottom -= SBarWidth;
- InsetRect(&(**TEH).viewRect, 4, 4);
- linesInFolder = ((**TEH).viewRect.bottom-(**TEH).viewRect.top)/(**TEH).lineHeight;
- (**TEH).viewRect.bottom = (**TEH).viewRect.top + (**TEH).lineHeight*linesInFolder;
- (**TEH).destRect.right = (**TEH).viewRect.right;
- TECalText(TEH);
- }
-
- UpdateWindow(theWindow)
- WindowPtr theWindow;
- {
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( theWindow );
- BeginUpdate( theWindow );
- EraseRect(&theWindow->portRect);
- DrawControls( theWindow );
- DrawGrowIcon( theWindow );
- TEUpdate( &theWindow->portRect, TEH );
- EndUpdate( theWindow );
- SetPort( savePort );
- }
-
- pascal void ScrollProc(theControl, theCode)
- ControlHandle theControl;
- int theCode;
- {
- int pageSize;
- int scrollAmt;
-
- if (theCode == 0)
- return ;
-
- pageSize = ((**TEH).viewRect.bottom-(**TEH).viewRect.top) /
- (**TEH).lineHeight - 1;
-
- switch (theCode) {
- case inUpButton:
- scrollAmt = -1;
- break;
- case inDownButton:
- scrollAmt = 1;
- break;
- case inPageUp:
- scrollAmt = -pageSize;
- break;
- case inPageDown:
- scrollAmt = pageSize;
- break;
- }
- SetCtlValue( theControl, GetCtlValue(theControl)+scrollAmt );
- AdjustText();
-
- }
-
- DoContent(theWindow, theEvent)
- WindowPtr theWindow;
- EventRecord *theEvent;
- {
- int cntlCode;
- ControlHandle theControl;
- int pageSize;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theWindow);
- GlobalToLocal( &theEvent->where );
- if ((cntlCode = FindControl(theEvent->where, theWindow, &theControl)) == 0) {
- if (PtInRect( theEvent->where, &(**TEH).viewRect ))
- TEClick( theEvent->where, (theEvent->modifiers & shiftKey )!=0, TEH);
- }
- else if (cntlCode == inThumb) {
- TrackControl(theControl, theEvent->where, 0L);
- AdjustText();
- }
- else
- TrackControl(theControl, theEvent->where, &ScrollProc);
-
- SetPort(savePort);
- }
-
- MyGrowWindow( w, p )
- WindowPtr w;
- Point p;
- {
- GrafPtr savePort;
- long theResult;
- int oScroll;
- Rect r, oView;
-
- GetPort( &savePort );
- SetPort( w );
-
- SetRect(&r, 80, 80, 2000, 2000); /* screenBits.bounds.right, screenBits.bounds.bottom */
- theResult = GrowWindow( w, p, &r );
- if (theResult == 0)
- return;
- SizeWindow( w, LoWord(theResult), HiWord(theResult), 1);
-
- InvalRect(&w->portRect);
- oView = (**TEH).viewRect;
- oScroll = GetCtlValue(vScroll);
-
- SetView(w);
- HidePen();
- MoveControl(vScroll, w->portRect.right - SBarWidth, w->portRect.top-1);
- SizeControl(vScroll, SBarWidth+1, w->portRect.bottom - w->portRect.top-(SBarWidth-2));
- ShowPen();
-
-
- SetVScroll();
- AdjustText();
-
- SetPort( savePort );
- }
-
- MySizeWindow( w, h, v )
- WindowPtr w;
- int h, v;
- {
- GrafPtr savePort;
- int oScroll;
- Rect r, oView;
-
- GetPort( &savePort );
- SetPort( w );
-
- SizeWindow( w, h, v, 1);
-
- InvalRect(&w->portRect);
- oView = (**TEH).viewRect;
- oScroll = GetCtlValue(vScroll);
-
- SetView(w);
- HidePen();
- MoveControl(vScroll, w->portRect.right - SBarWidth, w->portRect.top-1);
- SizeControl(vScroll, SBarWidth+1, w->portRect.bottom - w->portRect.top-(SBarWidth-2));
- ShowPen();
-
- SetVScroll();
- AdjustText();
-
- SetPort( savePort );
- }
-
- CloseMyWindow()
- {
- HideWindow( myWindow );
- TESetSelect( 0, (**TEH).teLength, TEH );
- TEDelete( TEH );
- SetVScroll();
- }
-
- /*=============================================================================
- TEClickLoop
-
- Function for auto-scrolling text
- =============================================================================*/
-
- static pascal Boolean ClickLoopProc()
- {
- Point mouseLoc;
- RgnHandle theRegion;
-
- theRegion = NewRgn();
- GetClip(theRegion);
- ClipRect(&myWindow->portRect);
-
- GetMouse(&mouseLoc);
- if (mouseLoc.v < 0) {
- SetCtlValue( vScroll, GetCtlValue(vScroll)-1 );
- AdjustText();
- }
- if (mouseLoc.v > (myWindow->portRect.bottom - 14)) {
- SetCtlValue( vScroll, GetCtlValue(vScroll)+1 );
- AdjustText();
- }
-
- SetClip(theRegion);
- DisposeRgn(theRegion);
- return(TRUE);
- }
-
- /*=============================================================================
- TEWordBreak
-
- =============================================================================*/
-
- static pascal Boolean WordBreakProc(text, charPos)
- char *text;
- int charPos;
- {
- char theChar, unbold;
-
- theChar = text[charPos];
- if (theChar < 0)
- theChar += 128;
- unbold = theChar - 128;
-
- if (theChar == '.' || theChar == '_' || theChar == '"' || theChar == ':' || theChar == '?' ||
- unbold == '.' || unbold == '_' || unbold == '"' || unbold == ':' || unbold == '?')
- return (FALSE); /* don't break on these typical logo-word characters */
-
- if (theChar <= 47) /* non-printing characters and symbols */
- return(TRUE);
- if (theChar <= 57) /* digits */
- return(FALSE);
- if (theChar <= 64) /* symbols */
- return(TRUE);
- if (theChar <= 90) /* capital letters */
- return(FALSE);
- if (theChar <= 96) /* symbols */
- return(TRUE);
- if (theChar <= 122) /* lower-case letters */
- return(FALSE);
- if (theChar <= 127) /* symbols */
- return(TRUE);
- if (theChar <= 159) /* foreign letters */
- return(FALSE);
- if (theChar <= 175) /* bold symbols */
- return(TRUE);
- if (theChar <= 185) /* bold digits */
- return(FALSE);
- if (theChar <= 192) /* bold symbols */
- return(TRUE);
- if (theChar <= 218) /* bold capital letters */
- return(FALSE);
- if (theChar <= 224) /* bold symbols */
- return(TRUE);
- if (theChar <= 250) /* bold lower-case letters */
- return(FALSE);
- return(TRUE); /* bold symbols */
- }
-