home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / os2cl016.zip / pmgpi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-26  |  8.1 KB  |  271 lines

  1. /* 
  2.  
  3.  
  4.     pmgpi.h (emx+gcc) 
  5.  
  6.     1995 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16. #ifndef _PMGPI_H_
  17. #define _PMGPI_H_
  18.  
  19. #include "pmsys.h"
  20.  
  21. class PMWin;
  22. class PMPoint;
  23. class PMRect;
  24. class PMPresSpace;
  25. class PMDevContext;
  26.  
  27. struct PMPoint : public POINTL {
  28.     PMPoint() { };
  29.     PMPoint(LONG ix,LONG iy=0) { x=ix; y=iy; }
  30.     
  31.     PMPoint& operator += (PMPoint& a) { x+=a.x; y+=a.y; return *this; }
  32.     PMPoint& operator -= (PMPoint& a) { x-=a.x; y-=a.y; return *this; }
  33.     PMPoint& operator = (POINTS a) { x=(LONG)a.x; y=(LONG)a.y; return *this; }
  34. };
  35.  
  36. inline PMPoint operator + (PMPoint& a,PMPoint& b) { 
  37.     PMPoint c; 
  38.     c.x=a.x+b.x; c.y=a.y+b.y; 
  39.     return c; 
  40. }
  41.  
  42. inline PMPoint operator - (PMPoint& a,PMPoint& b) { 
  43.     PMPoint c; 
  44.     c.x=a.x-b.x; c.y=a.y-b.y; 
  45.     return c; 
  46. }
  47.  
  48. inline PMPoint operator * (PMPoint& a,int b) { 
  49.     PMPoint c; 
  50.     c.x=a.x*b; c.y=a.y*b; 
  51.     return c; 
  52. }
  53.  
  54. inline PMPoint operator / (PMPoint& a,int b) { 
  55.     PMPoint c; 
  56.     c.x=a.x/b; c.y=a.y/b; 
  57.     return c; 
  58. }
  59.  
  60. struct PMRect : public RECTL {
  61.     PMRect(LONG x1, LONG y1, LONG x2, LONG y2) { 
  62.         xLeft=x1; yBottom=y1; xRight=x2; yTop=y2;
  63.     }
  64.     PMRect(PMPoint &p1, PMPoint &p2) { 
  65.         xLeft=p1.x; yBottom=p1.y; xRight=p2.x; yTop=p2.y;
  66.     }
  67.     PMRect(POINTL &p1, POINTL &p2) { 
  68.         xLeft=p1.x; yBottom=p1.y; xRight=p2.x; yTop=p2.y;
  69.     }
  70.     PMRect() { };
  71.     PMRect& operator = ( PMWin* );
  72.     PMRect& operator += (PMPoint& a) { 
  73.         xLeft+=a.x; xRight+=a.x;
  74.         yBottom+=a.y; yTop+=a.y;
  75.         return *this; 
  76.     }
  77.     PMRect& operator -= (PMPoint& a) { 
  78.         xLeft-=a.x; xRight-=a.x;
  79.         yBottom-=a.y; yTop-=a.y;
  80.         return *this; 
  81.     }
  82. };
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85.  
  86. class PMPointer {
  87.     HPOINTER ptr;
  88. public:
  89.     PMPointer(ULONG idres) {
  90.         ptr=WinLoadPointer (HWND_DESKTOP,NULLHANDLE,idres);
  91.     }
  92.     ~PMPointer() {
  93.         WinDestroyPointer(ptr);
  94.     }
  95.     void set() {
  96.         WinSetPointer(HWND_DESKTOP,ptr);
  97.     }
  98.     void reset() { // reset system pointer
  99.         WinSetPointer(HWND_DESKTOP,
  100.             WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE));
  101.     }
  102. };
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // logical fonts
  106.  
  107. class PMLogFont {
  108. protected:
  109.     FATTRS fat;
  110.     LONG lLcid;
  111. public:
  112.     friend PMPresSpace;
  113.  
  114.     PMLogFont(PMPresSpace& ps,PCCH szFacename, LONG lMaxBaselineExt, LONG lAveCharWidth, USHORT usCodePage);
  115.     PMLogFont(PMPresSpace& ps,PFATTRS pfAttrs);
  116. };
  117.  
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120.  
  121. class PMDeviceContext {
  122. protected:
  123.     HDC hdc;
  124.     HAB hab;
  125.     BOOL canClose; // if FALSE the destructor does not close the DC.
  126. public:
  127.     PMDeviceContext(HAB ab,HDC ihdc); // you can also open the DC later, specifing NULLHANDLE here 
  128.     PMDeviceContext(HAB ab,LONG lType, PCSZ pszToken="*", LONG lCount=0, PDEVOPENDATA pdopData=NULL, HDC hdcComp=NULLHANDLE); // oppure fai tutto subito.
  129.     PMDeviceContext(HWND hwnd);
  130.     virtual ~PMDeviceContext();
  131.     HDC open(LONG lType, PCSZ pszToken="*", LONG lCount=0, PDEVOPENDATA pdopData=NULL, HDC hdcComp=NULLHANDLE);
  132.     HMF close() { return DevCloseDC ( hdc); }
  133.     LONG escape(LONG lCode, LONG lInCount, PBYTE pbInData, PLONG plOutCount=NULL, PBYTE pbOutData=NULL) {
  134.         return DevEscape (hdc, lCode,lInCount, pbInData,plOutCount, pbOutData);
  135.     }    
  136.     BOOL queryCaps(LONG lStart, LONG lCount, PLONG alArray) {
  137.         return DevQueryCaps (hdc,lStart,lCount,alArray);
  138.     }
  139.     operator HDC () { return hdc; }
  140. };
  141.  
  142. class PMMemoryDC : public PMDeviceContext {
  143. protected:
  144. public:
  145.     PMMemoryDC(HAB ab);  // as above
  146.     PMMemoryDC(HAB ab,LONG lCount=0, HDC hdcComp=NULLHANDLE);
  147.     ~PMMemoryDC();
  148. };
  149.  
  150. class PMPrinterDC : public PMDeviceContext {
  151. protected:
  152.     DEVOPENSTRUC dop;
  153.     CHAR achPrnData[256],achDefPrnName[34];
  154.     DRIVDATA driv;
  155. public:
  156.     PMPrinterDC(HAB ab); // as above
  157.     PMPrinterDC(HAB ab,LONG lCount, PDEVOPENDATA pdopData, HDC hdcComp);
  158.     ~PMPrinterDC();
  159.     HDC open();
  160.     LONG startDoc(PSZ);
  161.     LONG endDoc(PSZ);
  162.     LONG newFrame();
  163.     LONG abortDoc();
  164.     BOOL getInformation(PSZ szDefPrnName,PSZ szPrnData,PDEVOPENSTRUC pdop);
  165. };
  166.  
  167. class PMPresSpace {
  168. protected:
  169.     HPS hps;
  170. public:
  171.     LONG lFontIdcount;
  172. public:
  173.     PMPresSpace() { lFontIdcount=1L; }
  174.     PMPresSpace(PMDeviceContext*,LONG width,LONG height,LONG flOptions,HAB ab);
  175.     virtual ~PMPresSpace();
  176.     operator HPS () { return hps; }
  177.  
  178.     BOOL setColor(LONG lColor) 
  179.         {     return GpiSetColor(hps,lColor); }
  180.     BOOL setLineType(LONG lLineType) 
  181.         {     return GpiSetLineType (hps, lLineType);    }
  182.     BOOL setDrawingMode (LONG lMode)
  183.         {    return GpiSetDrawingMode ( hps, lMode); }
  184.     BOOL openSegment (LONG lSegment) 
  185.         {    return GpiOpenSegment ( hps, lSegment); }
  186.     BOOL closeSegment () 
  187.         {    return GpiCloseSegment ( hps); }
  188.     BOOL drawSegment ( LONG lSegment)
  189.         {    return GpiDrawSegment ( hps, lSegment); }
  190.     BOOL setStopDraw (LONG lValue)
  191.         {    return GpiSetStopDraw ( hps, lValue); }
  192.  
  193.     BOOL restore ( LONG lPSid)
  194.         {    return GpiRestorePS ( hps, lPSid); }
  195.     LONG save ()
  196.         {    return GpiSavePS ( hps); }
  197.  
  198.     LONG drawText(LONG cchText, PCCH lpchText, PRECTL prcl, LONG clrFore, LONG clrBack, ULONG flCmd)
  199.         {    return WinDrawText(hps,cchText,lpchText,prcl,clrFore,clrBack,flCmd); }
  200.     BOOL fillRect(PRECTL rect, LONG lColor) 
  201.         {    return WinFillRect(hps, rect, lColor); }
  202.     LONG line(PPOINTL point) 
  203.         {    return GpiLine (hps, point); }
  204.     LONG move(PPOINTL point) 
  205.         {    return GpiMove (hps, point); }
  206.     BOOL setMix(LONG lMixMode) 
  207.         {    return GpiSetMix (hps, lMixMode); }
  208.     LONG box(LONG lControl, PPOINTL pptlPoint, LONG lHRound=0L, LONG lVRound=0L)
  209.         {     return GpiBox (hps, lControl, pptlPoint, lHRound, lVRound); }
  210.  
  211.     LONG intersectClipRectangle (__const__ RECTL *prclRectangle) 
  212.         {    return GpiIntersectClipRectangle (hps, prclRectangle); }
  213.  
  214.     HDC queryDevice() 
  215.         {     return GpiQueryDevice (hps); }
  216.     BOOL queryCharBox(PSIZEF psizfxSize) 
  217.         {     return GpiQueryCharBox (hps, psizfxSize); }
  218.     BOOL queryFontMetrics(PFONTMETRICS pfmMetrics) 
  219.         {     return GpiQueryFontMetrics (hps, sizeof(FONTMETRICS), pfmMetrics); }
  220.     BOOL queryPageViewport (PRECTL prclViewport)
  221.         {     return GpiQueryPageViewport (hps,prclViewport);    }
  222.     BOOL queryTextBox (LONG lCount1, PCH pchString, LONG lCount2, PPOINTL aptlPoints)
  223.         {     return GpiQueryTextBox (hps, lCount1, pchString, lCount2, aptlPoints); }
  224.     BOOL queryTextBox (PSZ pszString, LONG lCount2, PPOINTL aptlPoints);
  225.     LONG queryTextBoxWidth (PSZ pszString);
  226.     LONG queryTextBoxHeight (PSZ pszString);
  227.  
  228.     BOOL set(PSIZEL psizlsize,ULONG flOptions)
  229.         {    return GpiSetPS(hps,psizlsize,flOptions); }
  230.     BOOL setPageViewport (__const__ RECTL *prclViewport)
  231.         {    return GpiSetPageViewport (hps, prclViewport); }
  232.  
  233.     BOOL setCharSet(LONG llcid) 
  234.         {    return GpiSetCharSet (hps, llcid); }
  235.     BOOL setCharAngle (__const__ GRADIENTL *pgradlAngle)
  236.         {     return GpiSetCharAngle (hps,pgradlAngle); }
  237.     BOOL setCharBox (__const__ SIZEF *psizfxBox) 
  238.         {    return GpiSetCharBox (hps,psizfxBox); }
  239.     BOOL setCharBreakExtra (FIXED BreakExtra)
  240.         {    return GpiSetCharBreakExtra (hps,BreakExtra); }
  241.     BOOL setCharDirection (LONG lDirection)
  242.         {    return GpiSetCharDirection (hps, lDirection); }
  243.     BOOL setCharExtra (FIXED Extra)
  244.         {    return GpiSetCharExtra (hps, Extra); }
  245.     BOOL setCharMode (LONG lMode) 
  246.         {    return GpiSetCharMode (hps, lMode); }
  247.     BOOL setCharSet(PMLogFont& lf) 
  248.         {    return GpiSetCharSet (hps, lf.lLcid); }
  249.     LONG charString (LONG lCount, PCCH pchString)
  250.         {    return GpiCharString (hps, lCount, pchString); }
  251.     LONG charStringAt (__const__ POINTL *pptlPoint, LONG lCount, PCCH pchString)
  252.         {    return GpiCharStringAt (hps, pptlPoint, lCount, pchString); }
  253.     LONG createLogFont (__const__ STR8 *pName, LONG lLcid, __const__ FATTRS *pfatAttrs)
  254.         {    return GpiCreateLogFont (hps, pName, lLcid, pfatAttrs); }
  255. };
  256.  
  257. class PMWindowPresSpace : public PMPresSpace {
  258. public:
  259.     PMWindowPresSpace(PMWin*);
  260.     ~PMWindowPresSpace();
  261. };
  262.  
  263. class PMMicroCachedPresSpace : public PMPresSpace {
  264. public:
  265.     PMMicroCachedPresSpace(PMWin*);
  266.     ~PMMicroCachedPresSpace();
  267. };
  268.  
  269. #endif
  270.  
  271.