home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / FontMancer.sit / FontMancer / Common / FontDisplay.c < prev    next >
C/C++ Source or Header  |  1996-06-21  |  5KB  |  197 lines

  1. #include "FontMancer.h"
  2. #include "FontDisplay.h"
  3. #include "StandardMenu.h"
  4.  
  5. extern WindowPtr        gMainWindow;
  6. extern Str255            gSamplePhrase;
  7.  
  8. void UpdateMisc(WindowPtr    theWindow)
  9. {
  10.  
  11.     FMStuff            *FMStore;
  12.     Str255            updateText;        
  13.     
  14.     FMStore = (FMStuff *) GetWRefCon(theWindow);
  15.     if (RectInRgn(&(FMStore->itemRects[iTextRect1]),theWindow->visRgn)) {
  16.         MoveTo(FMStore->itemRects[iTextRect1].left,FMStore->itemRects[iTextRect1].bottom);
  17.         GetIndString(updateText,rDisplayStrings,1);
  18.         DrawString(updateText);
  19.         }
  20.     if (RectInRgn(&(FMStore->itemRects[iTextRect2]),theWindow->visRgn)) {
  21.         MoveTo(FMStore->itemRects[iTextRect2].left,FMStore->itemRects[iTextRect2].bottom);
  22.         GetIndString(updateText,rDisplayStrings,2);
  23.         DrawString(updateText);
  24.         }
  25.     if (RectInRgn(&(FMStore->itemRects[iMenuNameRect]),theWindow->visRgn)) {
  26.         MoveTo(FMStore->itemRects[iMenuNameRect].left,FMStore->itemRects[iMenuNameRect].bottom);
  27.         GetIndString(updateText,rDisplayStrings,3);
  28.         DrawString(updateText);
  29.     }
  30.     if (RectInRgn(&(FMStore->itemRects[iLineRect]),theWindow->visRgn))
  31.         FrameRect(&(FMStore->itemRects[iLineRect]));
  32.     if (RectInRgn(&(FMStore->itemRects[iSampleRect]),theWindow->visRgn)) {
  33.         FrameRect(&(FMStore->itemRects[iSampleRect]));
  34.         UpdateSampleRect(FMStore);
  35.     }
  36. }
  37.  
  38. void UpdateSampleRect(FMStuff *FMStore)
  39. {
  40.     Rect                sampleRect;
  41.     RgnHandle            oldClipRgn,clipRgn;
  42.     FontInfo            fInfo;
  43.     Fixed                textWidth;
  44.     short                lineDots, textVertical;
  45.     long                textOffset,textStart, textLength, textEnd;
  46.     StyledLineBreakCode    breakCode;
  47.     Ptr                    textPtr;
  48.     const short            sizeMenu[7] = {9,10,12,14,18,24,36};
  49.  
  50.     TextFont(FMStore->fontDisplayed);
  51.     TextFace(FMStore->fontStyle);
  52.     TextSize(sizeMenu[FMStore->fontSize]);
  53.     
  54.     SetRect(&sampleRect,FMStore->itemRects[iSampleRect].left,FMStore->itemRects[iSampleRect].top,
  55.         FMStore->itemRects[iSampleRect].right,FMStore->itemRects[iSampleRect].bottom);
  56.     InsetRect(&sampleRect,4,4);
  57.     EraseRect(&sampleRect);
  58.     
  59.     GetFontInfo(&fInfo);
  60.     lineDots = fInfo.ascent + fInfo.descent + fInfo.leading;
  61.     textVertical = sampleRect.top + fInfo.ascent;
  62.     MoveTo(sampleRect.left, textVertical);
  63.  
  64.     clipRgn = NewRgn();
  65.     oldClipRgn = NewRgn();
  66.     RectRgn(clipRgn,&sampleRect);
  67.     GetClip(oldClipRgn);
  68.     SetClip(clipRgn);
  69.     
  70.     textPtr = (Ptr) &gSamplePhrase[1];
  71.     textOffset = 1;
  72.     textStart = 0;
  73.     textLength = textEnd = gSamplePhrase[0];
  74.     textWidth = sampleRect.right - sampleRect.left;
  75.     textWidth <<= 16;
  76.     
  77.     do {
  78.         breakCode = StyledLineBreak(textPtr,textEnd, textStart,
  79.                     textEnd,0,&textWidth, &textOffset);
  80.         textLength = textOffset - textStart;
  81.         DrawText(&gSamplePhrase[1],textStart,textLength);
  82.         textStart += textLength;
  83.         textOffset = 1;
  84.         textVertical += lineDots;
  85.         MoveTo(sampleRect.left, textVertical);
  86.         textWidth = sampleRect.right - sampleRect.left;
  87.         textWidth <<= 16;
  88.     }    while ((breakCode != smBreakOverflow) && (textVertical < sampleRect.bottom));
  89.     
  90.     SetClip(oldClipRgn);
  91.     DisposeRgn(clipRgn);
  92.     DisposeRgn(oldClipRgn);
  93.     TextFont(systemFont);
  94.     TextFace(0);
  95.     TextSize(0);
  96. }
  97.  
  98. void SetStyleDisplay(short iMenuItem, short iButton, Style fontStyle)
  99. {
  100.     FMStuff                *FMStore;
  101.     Style                styleCheck;
  102.  
  103.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  104.     styleCheck = (FMStore->fontStyle & fontStyle);
  105.     FMStore->fontStyle ^= fontStyle;
  106.     if (FMStore->fontStyle) {
  107.         SetControlValue(FMStore->ctlHandles[iPlainButton],0);
  108.         ToggleMenu(FALSE,iPlain,mStyle);
  109.         }
  110.     else {
  111.         SetControlValue(FMStore->ctlHandles[iPlainButton],1);
  112.         ToggleMenu(TRUE,iPlain,mStyle);
  113.         }
  114.     if (styleCheck == fontStyle) {
  115.         SetControlValue(FMStore->ctlHandles[iButton],0);
  116.         ToggleMenu(FALSE,iMenuItem,mStyle);
  117.         }
  118.     else {
  119.         SetControlValue(FMStore->ctlHandles[iButton],1);
  120.         ToggleMenu(TRUE,iMenuItem,mStyle);
  121.         }
  122.     UpdateSampleRect(FMStore);
  123. }
  124.  
  125. void SetPlainDisplay()
  126. {
  127.     FMStuff *FMStore;
  128.  
  129.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  130.     SetControlValue(FMStore->ctlHandles[iPlainButton],1);
  131.     ToggleMenu(TRUE,iPlain,mStyle);
  132.     SetControlValue(FMStore->ctlHandles[iBoldButton],0);
  133.     ToggleMenu(FALSE,iBold,mStyle);
  134.     SetControlValue(FMStore->ctlHandles[iItalicButton],0);
  135.     ToggleMenu(FALSE,iItalic,mStyle);
  136.     SetControlValue(FMStore->ctlHandles[iUnderlineButton],0);
  137.     ToggleMenu(FALSE,iUnderline,mStyle);
  138.     SetControlValue(FMStore->ctlHandles[iOutlineButton],0);
  139.     ToggleMenu(FALSE,iOutline,mStyle);
  140.     SetControlValue(FMStore->ctlHandles[iShadowButton],0);
  141.     ToggleMenu(FALSE,iShadow,mStyle);
  142.     FMStore->fontStyle = 0;
  143.     UpdateSampleRect(FMStore);
  144. }
  145.  
  146. void SetBoldDisplay()
  147. {
  148.     SetStyleDisplay(iBold,iBoldButton,bold);
  149. }
  150.  
  151. void SetItalicDisplay()
  152. {
  153.     SetStyleDisplay(iItalic,iItalicButton,italic);    
  154. }
  155.  
  156. void SetUnderlineDisplay()
  157. {
  158.     SetStyleDisplay(iUnderline,iUnderlineButton,underline);
  159. }
  160.  
  161. void SetOutlineDisplay()
  162. {
  163.     SetStyleDisplay(iOutline,iOutlineButton,outline);
  164. }
  165.  
  166. void SetShadowDisplay()
  167. {
  168.     SetStyleDisplay(iShadow,iShadowButton,shadow);
  169. }
  170.  
  171. void HandleSizePopUp()
  172. {
  173.     FMStuff *FMStore;
  174.  
  175.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  176.     FMStore->fontSize = GetControlValue(FMStore->ctlHandles[iSizePopUp]) - 1;
  177.     UpdateSampleRect(FMStore);
  178. }
  179.  
  180. void SetSizeDisplay(Boolean increase)
  181. {
  182.     FMStuff            *FMStore;
  183.     short            size;
  184.     
  185.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  186.     size = FMStore->fontSize;
  187.     if (increase) {
  188.         if (size < 6)
  189.             size++;
  190.     }
  191.     else
  192.         if (size > 0)
  193.             size--;
  194.     SetControlValue(FMStore->ctlHandles[iSizePopUp],size + 1);
  195.     FMStore->fontSize = size;
  196.     UpdateSampleRect(FMStore);
  197. }