home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / asci20b1.zip / tool.c < prev    next >
Text File  |  1999-05-20  |  6KB  |  160 lines

  1. // ASCII Table 2.0
  2. // Copyright 1998 by D.J. van Enckevort
  3. // This program and sourcecode is released as freeware
  4. // You can use this code for your own programs
  5. // If you use it, please keep a notice of this copyright
  6.  
  7. #define INCL_WIN
  8. #define INCL_WINHOOKS
  9. #define INCL_PM
  10. #define INCL_GPI
  11. #include <os2.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "ascii.h"
  16. #include "tool.h"
  17.  
  18. void PrfLoadFont(HINI *pProfile, PFONTDLG pfd)
  19. {
  20. ULONG Size;
  21. int PointSize;
  22. char CurrentFont[FACESIZE];
  23. // Read the font dialog data
  24. // Set default pointsize
  25. PointSize=DEFAULT_POINTSIZE;
  26. // Set all values in the FONTDLG structure fd to zero
  27. memset(pfd, 0, sizeof(FONTDLG));
  28. // Fill the structure with the necessary data
  29. // set default fAttrs values
  30. memset(&pfd->fAttrs, 0, sizeof(FATTRS));
  31. pfd->fAttrs.usRecordLength=sizeof(FATTRS);
  32. pfd->fAttrs.usCodePage=DEFAULT_CODEPAGE;
  33. // read fAttrs values
  34. PrfQueryProfileData(*pProfile, "FontAttr", "PointSize", &PointSize, &Size);
  35. PrfQueryProfileData(*pProfile, "FontAttr", "fsSelection", &pfd->fAttrs.fsSelection, &Size);
  36. PrfQueryProfileData(*pProfile, "FontAttr", "lMatch", &pfd->fAttrs.lMatch, &Size);
  37. PrfQueryProfileString(*pProfile, "FontAttr", "Facename", "Helv", pfd->fAttrs.szFacename, FACESIZE);
  38. PrfQueryProfileData(*pProfile, "FontAttr", "isRegistry", &pfd->fAttrs.idRegistry, &Size);
  39. PrfQueryProfileData(*pProfile, "FontAttr", "usCodePage", &pfd->fAttrs.usCodePage, &Size);
  40. PrfQueryProfileData(*pProfile, "FontAttr", "lMaxBaselineExt", &pfd->fAttrs.lMaxBaselineExt, &Size);
  41. PrfQueryProfileData(*pProfile, "FontAttr", "fAveCharWidth", &pfd->fAttrs.lAveCharWidth, &Size);
  42. PrfQueryProfileData(*pProfile, "FontAttr", "fsType", &pfd->fAttrs.fsType, &Size);
  43. PrfQueryProfileData(*pProfile, "FontAttr", "fsFontUse", &pfd->fAttrs.fsFontUse, &Size);
  44. // size of the structure
  45. pfd->cbSize=sizeof(FONTDLG);
  46. DosAllocMem((PPVOID)&pfd->pszFamilyname, FACESIZE, PAG_COMMIT | PAG_READ | PAG_WRITE);
  47. pfd->pszFamilyname[0]=0;
  48. // Preferred point size
  49. pfd->fxPointSize=MAKEFIXED(PointSize,0);
  50. // Size of buffer for fontfamily name
  51. pfd->usFamilyBufLen=FACESIZE;
  52. // Default foreground colour
  53. pfd->clrFore=SYSCLR_WINDOWTEXT;
  54. // Default background colour
  55. pfd->clrBack=SYSCLR_WINDOW;
  56. // Dialog flags
  57. // Center dialog, and use font attributes
  58. pfd->fl=FNTS_CENTER | FNTS_INITFROMFATTRS;
  59. }
  60.  
  61. void PrfSaveFont(PFONTDLG pfd)
  62. {
  63. }
  64.  
  65. // Function to resize and move controls
  66. // Parameters:
  67. // hwnd Window handler of the main window
  68. // oldframe & newframe SWP structures which contain the old & new sizes of the main window
  69. //   used to calculate the new size and position of the client window
  70. // ID Resource ID of the client window
  71. void ResizeX(HWND hwnd, SWP oldframe, SWP newframe, ULONG ID)
  72. {
  73. // structure to store the current position and size
  74. SWP swp;
  75. // Flags to resize and move
  76. ULONG flags=SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE;
  77. // Query current position and size
  78. WinQueryWindowPos(WinWindowFromID(hwnd, ID), &swp);
  79. // Calculate the new position and size
  80. swp.y=swp.y+newframe.cy-oldframe.cy;
  81. swp.cx=swp.cx+newframe.cx-oldframe.cx;
  82. // Move and resize the control
  83. WinSetWindowPos(WinWindowFromID(hwnd, ID), NULL, swp.x, swp.y, swp.cx, swp.cy, flags);
  84. }
  85. // Function to move controls
  86. // Parameters:
  87. // hwnd Window handler of the main window
  88. // oldframe & newframe SWP structures which contain the old & new sizes of the main window
  89. // ID Resource ID of the client window
  90. void Move(HWND hwnd, SWP oldframe, SWP newframe, ULONG ID)
  91. {
  92. // structure to store the current position and size
  93. SWP swp;
  94. // Flags to move
  95. ULONG flags=SWP_ACTIVATE | SWP_SHOW | SWP_MOVE;
  96. // Query current position and size
  97. WinQueryWindowPos(WinWindowFromID(hwnd, ID), &swp);
  98. // Calculate the new position
  99. swp.y=swp.y+newframe.cy-oldframe.cy;
  100. // Move the control
  101. WinSetWindowPos(WinWindowFromID(hwnd, ID), NULL, swp.x, swp.y, swp.cx, swp.cy, flags);
  102. }
  103.  
  104.  
  105. // AddCPMenu()
  106. // Adds a menu with all available codepages
  107. void AddCPMenu(HWND hwndFrame)
  108. {
  109. ULONG CodePages[MAX_CP], CPs;
  110. MENUITEM mi;
  111. HWND hwndMenu, hwndSubMenu, hwndPullDown;
  112. int i;
  113. char CodePageString[10];
  114. hwndMenu=WinWindowFromID(hwndFrame, FID_MENU);
  115. WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(MI_CODEPAGE, TRUE), MPFROMP(&mi));
  116. hwndPullDown=mi.hwndSubMenu;
  117. CPs=WinQueryCpList(hab, MAX_CP, CodePages);
  118. for (i=0; i<CPs; i++)
  119.    {
  120.    mi.iPosition=MIT_END;
  121.    mi.afStyle=MIS_TEXT;
  122.    mi.afAttribute=0;
  123.    mi.id=1000+CodePages[i];
  124.    mi.hwndSubMenu=NULL;
  125.    mi.hItem=0;
  126.    sprintf(CodePageString, "%lu", CodePages[i]);
  127.    if (((i%15)==0) && (i!=0))
  128.       {
  129.       mi.afStyle=MIS_TEXT | MIS_BREAKSEPARATOR;
  130.       }
  131.    WinSendMsg(hwndPullDown, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(CodePageString));
  132.    }
  133. }
  134.  
  135. // Draw the ValueSet cell
  136. void DrawValueSet(POWNERITEM OwnerItem, PFATTRS fAttrs)
  137. {
  138. POINTL Point;
  139. char ch[CHAR_BUFFER];
  140. USHORT row, col;
  141. FONTMETRICS FontMetrics;
  142. GpiCreateLogFont(OwnerItem->hps, NULL, 1L, fAttrs);
  143. //GpiSetCp(OwnerItem->hps, fAttrs->usCodePage);
  144. GpiSetCharSet(OwnerItem->hps, 1L);
  145. row=SHORT1FROMMR(OwnerItem->hItem);
  146. col=SHORT2FROMMR(OwnerItem->hItem);
  147. row--;
  148. col--;
  149. ch[0]=row*MAX_COLUMN+col;
  150. ch[1]=0;
  151. Point.x=OwnerItem->rclItem.xLeft;
  152. Point.y=OwnerItem->rclItem.yBottom;
  153. GpiErase(OwnerItem->hps);
  154. GpiQueryFontMetrics(OwnerItem->hps, sizeof(FONTMETRICS), &FontMetrics);
  155. Point.y+=FontMetrics.lMaxDescender+((OwnerItem->rclItem.yTop-OwnerItem->rclItem.yBottom-FontMetrics.lMaxBaselineExt)/2);
  156. Point.x+=(OwnerItem->rclItem.xRight - OwnerItem->rclItem.xLeft - FontMetrics.lMaxCharInc) / 2;
  157. GpiSetAttrs(OwnerItem->hps, PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR, CBB_COLOR | CBB_BACK_COLOR, NULL);
  158. GpiCharStringAt(OwnerItem->hps, &Point, 1, ch);
  159. }
  160.