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

  1. #include "FontMancer.h"
  2. #include "FontDisplay.h"
  3. #include "Standard.h"
  4.  
  5. extern WindowPtr    gMainWindow;
  6. extern Str255        gSamplePhrase;
  7.  
  8. void FindPlaceInList(Point *testCell, Str255 resName, FMStuff *FMStore)
  9. {
  10.  
  11.     Str255    testName;
  12.     short    testLen = 255;
  13.  
  14.     SetPt(testCell,0,0);
  15.     if ((**FMStore->fontList).dataBounds.bottom == 0) return;
  16.     LGetCell(&testName[1], &testLen,*testCell,FMStore->fontList);
  17.     testName[0] = testLen;
  18.     while ((RelString(resName,testName,FALSE,TRUE) >= 0)) {
  19.         if (LNextCell(FALSE,TRUE,testCell,FMStore->fontList))
  20.         {
  21.             testLen = 255;
  22.             LGetCell(&testName[1],(short *) &testLen,*testCell,FMStore->fontList);
  23.             testName[0] = testLen;
  24.         }
  25.         else
  26.             break;
  27.     }
  28. }
  29.  
  30. void LoadFontInfo(FMStuff *FMStore)
  31. {
  32.     int                    loop;
  33.     //int                    index = 0;
  34.     //short                resID, checkChar, listLimit = 0;
  35.     int                    listLimit = 0;
  36.     Str255                tempStr = "\p";
  37.     Handle                resHandle;
  38.     //ResType                Type;
  39.     Point                cell;
  40.     CursHandle            hWatchCursor;
  41.     MenuHandle            tempFontMenu;
  42.  
  43.     hWatchCursor = GetCursor(watchCursor);
  44.     HLock((Handle) hWatchCursor);
  45.     SetCursor(*hWatchCursor);
  46.     tempFontMenu = NewMenu(300,tempStr);
  47.     AddResMenu(tempFontMenu,'FONT');
  48.     FMStore->numFonts = CountMItems(tempFontMenu);
  49.     for (loop = 1; loop <= FMStore->numFonts; loop++) {
  50.         GetItem(tempFontMenu,loop,tempStr);
  51.         listLimit += tempStr[0];
  52.         if (listLimit < 32000) {
  53.             SetPt(&cell,0,loop - 1);
  54.             //FindPlaceInList(&cell,tempStr,FMStore);
  55.             LAddRow(1,cell.v,FMStore->fontList);
  56.             LSetCell(&(tempStr[1]),tempStr[0],cell,FMStore->fontList);
  57.         }
  58.         else {
  59.             loop = FMStore->numFonts;
  60.             InfoAlert(infoLimitReached,NIL);
  61.         }
  62.     }
  63.     DisposeMenu(tempFontMenu);
  64.     /*for (loop = 1; loop <= FMStore->numFonts; loop++) {
  65.         resHandle = GetIndResource('FOND',loop);
  66.         GetResInfo(resHandle,&resID,&Type,resName);
  67.         checkChar = resName[1];
  68.         if ((checkChar >= 'a' && checkChar <= 'z') ||
  69.             (checkChar >='A' && checkChar <='Z')) {
  70.             listLimit += resName[0];
  71.             if (listLimit < 32000) {
  72.                 SetPt(&cell,0,loop - 1);
  73.                 FindPlaceInList(&cell,resName,FMStore);
  74.                 LAddRow(1,cell.v,FMStore->fontList);
  75.                 LSetCell(&(resName[1]),resName[0],cell,FMStore->fontList);
  76.             }
  77.             else {
  78.                 loop = FMStore->numFonts;
  79.                 InfoAlert(infoLimitReached,NIL);
  80.             }
  81.         }
  82.         ReleaseResource(resHandle);
  83.     }*/
  84.     
  85.     HUnlock((Handle) hWatchCursor);
  86.     SetCursor(&qd.arrow);
  87.     ReleaseResource((Handle) hWatchCursor);
  88. }
  89.  
  90. void InitFontListVars(FMStuff *FMStore)
  91. {
  92.     //FMStore->numFonts = CountResources('FOND');
  93.     FMStore->fontStyle = FMStore->fontDisplayed = 0;
  94.     FMStore->fontSize = 2;
  95. }
  96.  
  97. void SetDisplayFont(Point selectedCell, FMStuff *FMStore)
  98. {
  99.     short    cellDataLen;
  100.     Str255    cellData;
  101.  
  102.     cellDataLen = 255;
  103.     LGetCell(&cellData[1],&cellDataLen,selectedCell,FMStore->fontList);
  104.     cellData[0] = cellDataLen;
  105.     GetFNum(cellData,&FMStore->fontDisplayed);
  106. }
  107.  
  108. void CreateFontList()
  109. {
  110.     Rect                dataBounds,itemRect;
  111.     Point                cellSize;
  112.     FMStuff                *FMStore;
  113.     
  114.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  115.     InitFontListVars(FMStore);
  116.     SetPt(&cellSize,0,0);
  117.     SetRect(&dataBounds,0,0,1,0);
  118.     SetRect(&itemRect,FMStore->itemRects[iListRect].left,FMStore->itemRects[iListRect].top,
  119.             FMStore->itemRects[iListRect].right,FMStore->itemRects[iListRect].bottom);
  120.     itemRect.right -= 15; //pull it in so as not to kill the vertical scroll bar
  121.     FMStore->fontList = LNew(&itemRect,&dataBounds,cellSize,0,gMainWindow,
  122.                                 FALSE,FALSE,FALSE,TRUE);
  123.     HLock((Handle)FMStore->fontList);
  124.     (**FMStore->fontList).selFlags = lOnlyOne | lNoNilHilite;
  125.     LoadFontInfo(FMStore);
  126.     SetPt(&cellSize,0,0);
  127.     LSetSelect(TRUE,cellSize,FMStore->fontList);
  128.     SetDisplayFont(cellSize,FMStore);
  129.     LDoDraw(TRUE,FMStore->fontList);
  130.     HUnlock((Handle)FMStore->fontList);
  131. }
  132.  
  133. void DisposeFontList()
  134. {
  135.     FMStuff *FMStore;
  136.  
  137.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  138.     LDispose(FMStore->fontList);
  139.     DisposePtr((Ptr) FMStore);
  140. }
  141.  
  142. void DrawBorder(Rect borderRect)
  143. {
  144.     PenState    savethePen;
  145.     
  146.     GetPenState(&savethePen);
  147.     PenSize(1,1);
  148.     InsetRect(&borderRect,-1,-1);
  149.     FrameRect(&borderRect);
  150.     SetPenState(&savethePen);
  151. }
  152.  
  153. void    UpdateFontList(WindowPtr theWin)
  154. {
  155.     FMStuff    *FMStore;
  156.     
  157.     FMStore = (FMStuff *) GetWRefCon(theWin);
  158.     HLock((Handle)FMStore->fontList);
  159.     LUpdate(theWin->visRgn,FMStore->fontList);
  160.     DrawBorder((**FMStore->fontList).rView);
  161.     HUnlock((Handle)FMStore->fontList);
  162. }
  163.  
  164. void HandleListSelect(EventRecord *event)
  165. {
  166.     Point                mouseLoc, selectedCell;
  167.     FMStuff                *FMStore;
  168.     short                ignored;
  169.     ListHandle            theList;
  170.     
  171.     SetPt(&mouseLoc,event->where.h,event->where.v);
  172.     GlobalToLocal(&mouseLoc);
  173.     FMStore = (FMStuff *) GetWRefCon(gMainWindow);
  174.     theList = FMStore->fontList;
  175.     HLock((Handle) theList);
  176.     ignored = LClick(mouseLoc,event->modifiers,theList);
  177.     SetPt(&selectedCell,0,0);
  178.     if (LGetSelect(TRUE,&selectedCell,theList)) {
  179.         SetDisplayFont(selectedCell,FMStore);
  180.         UpdateSampleRect(FMStore);
  181.     }
  182.     HUnlock((Handle) theList);
  183. }