home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Libraries / RgnMaster 1.0 / Source / Otherlies / Help Window.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  4.8 KB  |  188 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.         Help Window.c++
  4.         by Hiep Dam, 3G Software.
  5.         March 1994.
  6.         Last Update April 1994
  7.         Contact: America Online: Starlabs
  8.                  Delphi        : StarLabs
  9.                  Internet      : starlabs@aol.com
  10.                               or starlabs@delphi.com
  11.  
  12.         Much of this code (especially scrolling) is by Dana Basken.
  13.         Thanks Dana!
  14.  
  15. */
  16.  
  17. #include "QDUtils.h"
  18. #include "Compat.h"
  19. #include "Help Window.h"
  20.  
  21. enum {
  22.     kHelpTextID = 128
  23. };
  24.  
  25. WindowPtr gHelpWindow;
  26. Handle gHelpText;
  27. TEHandle gHelpTE;
  28. StScrpHandle gHelpStyle;
  29. ControlHandle gScrollbar;
  30. Rect gHelpWindowBounds;
  31. Rect gTextFrame;
  32. Rect gTextView;
  33.  
  34. void InitHelpWindow() {
  35.     GrafPtr savePort;
  36.     Rect textView, textFrame, scrollRect;
  37.     short lineHeight, ascent;
  38.     TextStyle theStyle;
  39.  
  40.     GetPort(&savePort);
  41.  
  42.     SetRect(&gHelpWindowBounds, 0, 0, 400, 300);
  43.     SetRect(&gTextFrame, gHelpWindowBounds.left + 2, gHelpWindowBounds.top + 4,
  44.         gHelpWindowBounds.right - 2 - 16, gHelpWindowBounds.bottom - 4);
  45.     SetRect(&scrollRect, gTextFrame.right - 1, 4, gTextFrame.right - 1 + 16, 296);
  46.     gTextView = gTextFrame;
  47.     InsetRect(&gTextView, 4, 2);
  48.  
  49.     CenterRect(&gHelpWindowBounds, &screenBits.bounds);
  50.     if (gEnviron.hasColor)
  51.         gHelpWindow = NewCWindow(nil, &gHelpWindowBounds, "\pRgnMaster Help & Information",
  52.             false, noGrowDocProc, nil, true, 0);
  53.     else
  54.         gHelpWindow = NewWindow(nil, &gHelpWindowBounds, "\pRgnMaster Help & Information",
  55.             false, noGrowDocProc, nil, true, 0);
  56.     SetPort(gHelpWindow);
  57.  
  58.     gHelpStyle = (StScrpHandle)GetNamedResource('styl', "\pHelp");
  59.     HLockHi((Handle)gHelpStyle);
  60.     gHelpText = GetNamedResource('TEXT', "\pHelp");
  61.     HLockHi(gHelpText);
  62.  
  63.     gHelpTE = TEStylNew(&gTextView, &gTextView);
  64.     TEStylInsert(*gHelpText, GetHandleSize(gHelpText), gHelpStyle, gHelpTE);
  65.     TECalText(gHelpTE);
  66.  
  67.     // Get lineheight, at arbitrary character 100 (just a random pick).
  68.     // Need the lineheight in order to determine # of lines for the scrollbar
  69.     TEGetStyle(100, &theStyle, &lineHeight, &ascent, gHelpTE);
  70.     gScrollbar = NewControl(gHelpWindow, &scrollRect, "\pScroll", true, 1, 1,
  71.         (**gHelpTE).nLines - ((gTextView.bottom - gTextView.top) / lineHeight) + 1,
  72.         scrollBarProc, 0);
  73.  
  74.     HUnlock((Handle)gHelpStyle);
  75.     ReleaseResource((Handle)gHelpStyle);
  76.     HUnlock(gHelpText);
  77.     ReleaseResource(gHelpText);
  78.  
  79.     SetPort(savePort);
  80. } // END InitHelpWindow
  81.  
  82. void ShowHelpWindow() {
  83.     ShowWindow(gHelpWindow);
  84.     SelectWindow(gHelpWindow);
  85. } // END ShowHelpWindow
  86.  
  87. void HideHelpWindow() {
  88.     TextStyle theStyle;
  89.     short lineHeight, ascent;
  90.     short curVal;
  91.  
  92.     HideWindow(gHelpWindow);
  93.  
  94.     TEGetStyle(100, &theStyle, &lineHeight, &ascent, gHelpTE);
  95.     curVal = GetCtlValue(gScrollbar);
  96.     TEScroll(0, lineHeight * (curVal-1), gHelpTE);
  97.     SetCtlValue(gScrollbar, 1);
  98. } // END HideHelpWindow
  99.  
  100. void UpdateHelpWindow() {
  101.     GrafPtr savePort;
  102.     
  103.     GetPort(&savePort);
  104.  
  105.     SetPort(gHelpWindow);
  106.     EraseRect(&gTextFrame);
  107.     TEUpdate(&gTextView, gHelpTE);
  108.     FrameRect(&gTextFrame);
  109.     DrawControls(gHelpWindow);
  110.  
  111.     SetPort(savePort);
  112. } // END UpdateHelpWindow
  113.  
  114. pascal void HelpWindowScrollProc(ControlHandle theControl, short actionPart) {
  115.     TextStyle theStyle;
  116.     short lineHeight, ascent;
  117.  
  118.     short minVal = GetCtlMin(theControl);
  119.     short maxVal = GetCtlMax(theControl);
  120.     short curVal = GetCtlValue(theControl);
  121.     short oldVal = curVal;
  122.  
  123.     TEGetStyle(100, &theStyle, &lineHeight, &ascent, gHelpTE);
  124.  
  125.     switch(actionPart) {
  126.         case inUpButton:
  127.             if (curVal != minVal) {
  128.                 SetCtlValue(theControl, curVal - 1);
  129.                 TEScroll(0, lineHeight, gHelpTE);
  130.             }
  131.         break;
  132.         
  133.         case inDownButton:
  134.             if (curVal != maxVal) {
  135.                 SetCtlValue(theControl, curVal + 1);
  136.                 TEScroll(0, -lineHeight, gHelpTE);
  137.             }
  138.         break;
  139.         
  140.         case inPageUp:
  141.             // Attempt to move control up 1/8 of total
  142.             curVal -= ((maxVal - minVal) / 8);
  143.             if (curVal < minVal)
  144.                 curVal = minVal;
  145.             SetCtlValue(theControl, curVal);
  146.             TEScroll(0, lineHeight * (oldVal - curVal), gHelpTE);
  147.         break;
  148.         
  149.         case inPageDown:
  150.             curVal += ((maxVal - minVal) / 8);
  151.             if (curVal > maxVal)
  152.                 curVal = maxVal;
  153.             SetCtlValue(theControl, curVal);
  154.             TEScroll(0, lineHeight * (oldVal - curVal), gHelpTE);
  155.         break;
  156.     } // END switch
  157. } // END HelpWindowScroll
  158.  
  159. void ScrollHelpWindow(Point mouseLoc) {
  160.     ControlHandle hitControl;
  161.     short hitLoc, dummy, oldVal, curVal;
  162.     
  163.     hitLoc = FindControl(mouseLoc, gHelpWindow, &hitControl);
  164.     if (hitControl == gScrollbar) {
  165.         switch(hitLoc) {
  166.             case inUpButton:
  167.             case inDownButton:
  168.             case inPageUp:
  169.             case inPageDown:
  170.                 dummy = TrackControl(hitControl, mouseLoc, (ProcPtr)HelpWindowScrollProc);
  171.             break;
  172.             
  173.             case inThumb:
  174.                 TextStyle theStyle;
  175.                 short lineHeight, ascent;
  176.                 TEGetStyle(100, &theStyle, &lineHeight, &ascent, gHelpTE);
  177.  
  178.                 oldVal = GetCtlValue(hitControl);
  179.                 dummy = TrackControl(hitControl, mouseLoc, nil);
  180.                 curVal = GetCtlValue(hitControl);
  181.                 if (oldVal != curVal)
  182.                     TEScroll(0, lineHeight * (oldVal - curVal), gHelpTE);
  183.             break;
  184.         }
  185.     }
  186. } // END ScrollHelpWindow
  187.  
  188. // END Help Window.c++