home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyLogWindow.p < prev    next >
Encoding:
Text File  |  1994-08-04  |  3.4 KB  |  155 lines  |  [TEXT/PJMM]

  1. unit MyLogWindow;
  2.  
  3. interface
  4.  
  5.     const
  6.         rows = 100;
  7.  
  8.     var
  9.         log_window: windowPtr;
  10.         hide_log_window_in_background: boolean;
  11.  
  12.     procedure InitLogWindow;
  13.     procedure ShowLogWindow;
  14.     procedure FinishLogWindow;
  15.     function HandleLogWindowEvents (var er: eventRecord): boolean;
  16.     procedure LogToWindow (s: str255);
  17. { returns true if we handle it }
  18. { You can safely call HandleLogWindowEvents and LogToWindow even if InitLogWindow is not called, it will bounce,}
  19. { since log_window defaults to nil }
  20.  
  21. implementation
  22.  
  23.     uses
  24.         MyTypes;
  25.  
  26.     var
  27.         lh: listHandle;
  28.  
  29.     procedure LogToWindow (s: str255);
  30.         var
  31.             c: cell;
  32.     begin
  33.         if log_window <> nil then begin
  34.             if lh^^.dataBounds.bottom >= rows then
  35.                 LDelRow(1, 0, lh);
  36.             c.v := LAddRow(1, lh^^.dataBounds.bottom, lh);
  37.             c.h := 0;
  38.             LSetCell(@s[1], length(s), c, lh);
  39.             LScroll(0, rows, lh);
  40.         end;
  41.     end;
  42.  
  43.     procedure InitLogWindow;
  44.         var
  45.             view, bounds: rect;
  46.             size: point;
  47.     begin
  48.         SetRect(view, 10, 40, 500, 40 + 16 * 14);
  49.         log_window := NewWindow(nil, view, 'Log Window', false, noGrowDocProc, POINTER(-1), false, 0);
  50.         SetPort(log_window);
  51.         SetRect(bounds, 0, 0, 1, 0);
  52.         OffsetRect(view, -view.left, -view.top);
  53.         view.right := view.right - 15;
  54.         Setpt(size, 0, 0);
  55.         lh := LNew(view, bounds, size, 0, log_window, false, false, false, true);
  56.     end;
  57.  
  58.     procedure ShowLogWindow;
  59.     begin
  60.         if log_window <> nil then begin
  61.             LDoDraw(true, lh);
  62.             ShowWindow(log_window);
  63.         end;
  64.     end;
  65.  
  66.     procedure FinishLogWindow;
  67.     begin
  68.         if log_window <> nil then begin
  69.             LDispose(lh);
  70.             DisposeWindow(log_window);
  71.         end;
  72.     end;
  73.  
  74.     function HandleLogWindowEvents (var er: eventRecord): boolean;
  75.         procedure DoDrag (where: point);
  76.             var
  77.                 temprect: rect;
  78.                 bnds1, bnds2: point;
  79.         begin
  80.             temprect := GetGrayRgn^^.rgnBBox;
  81.             bnds1 := log_window^.portBits.bounds.topleft;
  82.             DragWindow(log_window, where, temprect);
  83.             bnds2 := log_window^.portBits.bounds.topleft;
  84.         end;
  85.         var
  86.             twp: windowPtr;
  87.             code: integer;
  88.             dummy, didit: boolean;
  89.     begin
  90.         didit := false;
  91.         if log_window <> nil then begin
  92.             case er.what of
  93.                 MouseDown:  begin
  94.                     code := FindWindow(er.where, twp);
  95.                     if (twp <> nil) & (twp = log_window) then begin
  96.                         SetPort(log_window);
  97.                         if (FrontWindow <> log_window) then begin
  98.                             if (BAND(er.modifiers, cmdKey) = 0) or (code <> inDrag) then
  99.                                 SelectWindow(log_window);
  100.                             if code = inDrag then
  101.                                 DoDrag(er.where);
  102.                             didit := true;
  103.                         end
  104.                         else
  105.                             case code of
  106.                                 InDrag:  begin
  107.                                     DoDrag(er.where);
  108.                                     didit := true;
  109.                                 end;
  110.                                 inContent, inGrow:  begin
  111.                                     GlobalToLocal(er.where);
  112.                                     dummy := LClick(er.where, er.modifiers, lh);
  113.                                     didit := true;
  114.                                 end;
  115.                                 otherwise
  116.                                     ;
  117.                             end;
  118.                     end;
  119.                 end;
  120.  
  121.                 keyDown, autoKey: 
  122.                     ;
  123.  
  124.                 UpdateEvt: 
  125.                     if windowPtr(er.message) = log_window then begin
  126.                         BeginUpdate(log_window);
  127.                         LUpdate(log_window^.visRgn, lh);
  128.                         EndUpdate(log_window);
  129.                         didit := true;
  130.                     end;
  131.  
  132.                 kOSEvent:  begin
  133.                     if BAND(BROTL(er.message, 8), $FF) = kSuspendResumeMessage then begin
  134.                         if BAnd(er.message, kResumeMask) <> 0 then
  135.                             ShowWindow(log_window)
  136.                         else if hide_log_window_in_background then
  137.                             HideWindow(log_window);
  138.                         InitCursor;
  139.                     end;
  140.                 end;
  141.  
  142.                 ActivateEvt:  begin
  143.                     if windowPtr(er.message) = log_window then begin
  144.                         LActivate(odd(er.modifiers), lh);
  145.                         didit := true;
  146.                     end;
  147.                 end;
  148.  
  149.                 otherwise
  150.             end;
  151.         end;
  152.         HandleLogWindowEvents := didit;
  153.     end;
  154.  
  155. end.