home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / DinkClas8⁄93 / DinkClass Expo93 / DC TextEdit / DTEditWind.c < prev    next >
Encoding:
Text File  |  1992-12-31  |  3.9 KB  |  229 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        DTEditWindow.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    © 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. // This is the class definition of DTEditWind
  12.  
  13. #include "DTEditDoc.h"
  14. #include "DTEditWind.h"
  15. #include "DApplication.h"
  16. #include <DinkUtils.h>
  17.  
  18.  
  19. DTEditWind::DTEditWind(void)
  20. {
  21.     //stub
  22. }
  23.  
  24. DTEditWind::~DTEditWind(void)
  25. {
  26.     //stub
  27. }
  28.  
  29.  
  30.  
  31. Boolean DTEditWind::Init(DDocument *doc, Boolean hasColorWindows)
  32. {
  33.     Boolean inheritedSuccess;
  34.     Rect vRect;
  35.     
  36.     inheritedSuccess = inherited::Init(doc, hasColorWindows);
  37.  
  38.     fDocText = ((DTEditDoc*)doc)->fText;
  39.     
  40.     fNextHandler = doc;
  41.     SetPort(fWindowPtr);
  42.     ( *fDocText)->inPort = fWindowPtr;
  43.     ( *fDocText)->txSize = 9;
  44.     ( *fDocText)->txFont = monaco;
  45.     
  46.     fVMax = (*fDocText)->nLines * (*fDocText)->lineHeight;
  47.     fVMin = 0;
  48.     
  49.     fHMax = ( (*fDocText)->destRect.right - (*fDocText)->destRect.left );
  50.     fHMin = 0;
  51.     
  52.     return (inheritedSuccess);
  53. }// end of init function
  54.  
  55.  
  56.  
  57. void DTEditWind::SynchScrollBars(void)
  58. {
  59.     Rect visible, dest;
  60.     
  61.     visible = (*fDocText)->viewRect;
  62.     dest = (*fDocText)->destRect;
  63.  
  64.     fVMax = (*fDocText)->nLines * (*fDocText)->lineHeight;
  65.     fVMin = 0;
  66.     
  67.     fVOffSet = visible.top - dest.top;
  68.     fHOffSet = visible.left - dest.left;
  69.         
  70.     inherited::SynchScrollBars();
  71. }// end of SynchScrollBars member function
  72.  
  73.  
  74.  
  75. void DTEditWind::HandleKeyDown(EventRecord *theEvent)                
  76. {
  77.     TEKey(LoWrd(theEvent->message), fDocText);
  78.     fDoc->fNeedToSave = TRUE;
  79.     SynchScrollBars();
  80.  
  81. } // end of HandleKeyDown member function
  82.  
  83.  
  84. void DTEditWind::HandleActivateEvt(EventRecord *theEvent)
  85. {
  86.     Boolean    activating;
  87.     
  88.     inherited:: HandleActivateEvt(theEvent);
  89.     
  90.     activating = (theEvent->modifiers & activeFlag);
  91.     if(activating)
  92.     {
  93.         TEActivate( fDocText );
  94.     }
  95.     else
  96.     {
  97.         TEDeactivate( fDocText );
  98.     }
  99.     
  100.     inherited:: HandleActivateEvt(theEvent);
  101.  
  102. }// end of HandleActivateEvt member function
  103.  
  104.  
  105. void DTEditWind::HandleOSEvent(EventRecord *theEvent)
  106. {
  107.     if(gApplication->fInBackground)
  108.     {
  109.         TEDeactivate( fDocText );
  110.     }
  111.     else
  112.     {
  113.         TEActivate( fDocText );
  114.     }
  115.     
  116.     inherited::HandleOSEvent(theEvent);
  117.         
  118. }// end of HandleActivateEvt member function
  119.  
  120.  
  121.  
  122. void DTEditWind::HandleNullEvent(EventRecord *theEvent)
  123. {
  124.     Rect    r;
  125.     Point whereIsMouse;
  126.     GrafPtr    oldPort;
  127.     CursHandle    IBeam;
  128.  
  129.     if (!gApplication->fInBackground)
  130.     {
  131.         GetPort(&oldPort);
  132.         SetPort(fWindowPtr);
  133.         GetMouse(&whereIsMouse);
  134.     
  135.         GetContentRect(&r);
  136.         if( PtInRect(whereIsMouse, &r) )
  137.         {
  138.             IBeam = GetCursor(iBeamCursor);
  139.             if(IBeam != NULL)
  140.                 SetCursor(*IBeam);
  141.             
  142.         }
  143.         else
  144.             InitCursor();
  145.     
  146.         SetPort(oldPort);
  147.         TEIdle( fDocText );
  148.     }// end if in forground
  149. }
  150.  
  151.  
  152.  
  153. void    DTEditWind::DoContent(EventRecord* theEvent)
  154. {    
  155.     Rect contents;
  156.     Boolean shiftOn;
  157.     Point    newPoint;
  158.     
  159.     shiftOn = ( (theEvent->modifiers & shiftKey) != 0);
  160.     FocusOnWindow();
  161.     GlobalToLocal(&theEvent->where);
  162.     GetContentRect(&contents);
  163.     if(PtInRect(theEvent->where, &contents))
  164.     {        
  165.         TEClick(theEvent->where, shiftOn, fDocText);
  166.     }// end if in content rect
  167.     else
  168.         ScrollClick(theEvent);
  169.  
  170. }// end of DoContent function
  171.  
  172.  
  173. void    DTEditWind::Draw(Rect *r)
  174. {
  175.     if( fDocText)
  176.     {
  177.         EraseRect(r);
  178.         TEUpdate(r, fDocText);
  179.     }
  180.     
  181. }// end of Draw member function
  182.  
  183.  
  184. // the grow methods only need to update the viewRect for the TEHandle
  185. void    DTEditWind::DoGrow(EventRecord *theEvent)
  186. {
  187.     Rect r;
  188.     
  189.     inherited::DoGrow(theEvent);
  190.     
  191.     GetContentRect(&r);
  192.     (**fDocText).viewRect = r;
  193.     
  194. }// end of DoGrow override
  195.  
  196. void    DTEditWind ::DoZoom(short partCode)
  197. {
  198.     Rect r;
  199.  
  200.     inherited::DoZoom(partCode);
  201.     
  202.     GetContentRect(&r);
  203.     (**fDocText).viewRect = r;
  204.     
  205. }// end of DoZoom member function
  206.  
  207.  
  208.  
  209. void    DTEditWind::ScrollContents(short dh, short dv)
  210. {
  211.  
  212.     TEScroll(dh, dv, fDocText );
  213.     
  214.     fVOffSet = (*fDocText)->viewRect.top - (*fDocText)->destRect.top;
  215.     fHOffSet = (*fDocText)->viewRect.left - (*fDocText)->destRect.left;
  216.     
  217. }// end of ScrollContents function
  218.  
  219.  
  220. void    DTEditWind::FocusOnContent(void)
  221. {
  222.     Rect r;
  223.     
  224.     SetPort(fWindowPtr);
  225.     GetContentRect(&r);
  226.     ClipRect(&r);
  227.     
  228. }// end of FocusOnContent member
  229.