home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / os2 / hpgl312.zip / TO_PM.C < prev    next >
C/C++ Source or Header  |  1993-04-18  |  7KB  |  245 lines

  1. /*
  2.    Copyright (c) 1991 - 1993 Heinz W. Werntges.  All rights reserved.
  3.    Distributed by Free Software Foundation, Inc.
  4.  
  5. This file is part of HP2xx.
  6.  
  7. HP2xx is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  9. to anyone for the consequences of using it or for whether it serves any
  10. particular purpose or works at all, unless he says so in writing.  Refer
  11. to the GNU General Public License, Version 2 or later, for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. HP2xx, but only under the conditions described in the GNU General Public
  15. License.  A copy of this license is supposed to have been
  16. given to you along with HP2xx so you can know your rights and
  17. responsibilities.  It should be in a file named COPYING.  Among other
  18. things, the copyright notice and this notice must be preserved on all
  19. copies.
  20.  
  21. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22. */
  23.  
  24. /** to_pm.c: OS/2 Presentation Manager preview for HP2xx
  25.  **
  26.  ** 92/10/26  V 1.00  HWW  Originating, based on some code from H. Szillat
  27.  ** 92/12/20  V 1.10  HWW  Considered usable after trial-and-error improvements
  28.  **
  29.  ** NOTES:
  30.  **   1) This is beta software (actually, my first PM project)
  31.  **      - so don't expect a clean code (yet).
  32.  **
  33.  **   2) Currently, I do not intend to support this PM previewer beyond
  34.  **      the time when the full-screen OS/2 previewer (based on emx 0.8f)
  35.  **      becomes available. This is mainly due to two reasons:
  36.  **         -- The PM version lacks a redirector of stderr into a separate
  37.  **            window. I don't know how to write one nor am I willing to.
  38.  **         -- The full-screen version should run on both DOS (386, 486)
  39.  **            and OS/2 2.x.
  40.  **      However, I am aware that a PM version is desirable. Does anyone
  41.  **      out there know an EASY way how to redirect hp2xx's outputs from
  42.  **      stderr into a window without changing hp2xx itself??
  43.  **/
  44.  
  45. #include <os2emx.h>
  46. #include <dos.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stdio.h>
  50. #include "bresnham.h"
  51. #include "hp2xx.h"
  52.  
  53. #define far    /* Not needed in 32 bit mode    */
  54.  
  55. HAB    hab;
  56. HPS    hps;
  57. HMQ    hmq;
  58. HWND    hwndFrame, hwndClient;
  59. QMSG    qmsg;
  60. RECTL    rctl;
  61.  
  62. static    PicBuf    *pbuf;
  63.  
  64.  
  65. /* Leftover from HS's compiler ? :    */
  66.  
  67. #pragma call(same_ds => off)
  68. #pragma data(heap_size=> 3000)
  69.  
  70.  
  71. /**
  72.  ** Screen sizes (in pels):
  73.  **/
  74. static int    scr_width;
  75. static int    scr_height;
  76.  
  77.  
  78. void repaint(HWND hwnd)
  79. {
  80. int    row_c, x;
  81. POINTL    ptl;
  82. RowBuf    *row;
  83.  
  84.   WinQueryUpdateRect (hwnd, &rctl);
  85.   hps = WinBeginPaint(hwnd,NULL,&rctl);
  86.   if (hps == NULL)
  87.   {
  88.     DosBeep( 1760, 300);
  89.     return;
  90.   }
  91.   GpiErase(hps);    /* Should fill rctl with "background"    */
  92.  
  93. /**
  94.  ** Drawing routine: Set all non-background pels within invalid rctl
  95.  **
  96.  ** NOTE: There might be much faster bitblt ops available, but we have
  97.  ** to cope here with the internal bitmap, which must remain portable,
  98.  ** and the easiest *portable* bitblt works bit-by-bit.
  99.  **/
  100.   for (row_c=ptl.y=rctl.yBottom; row_c < rctl.yTop; row_c++,ptl.y++)
  101.   {
  102.     row = get_RowBuf (pbuf, row_c);
  103.     for (x=rctl.xLeft; x < rctl.xRight; x++)
  104.     {
  105.         switch (index_from_RowBuf(row, x, pbuf))
  106.         {
  107.           case xxBackground:                    continue;
  108.           case xxForeground:    GpiSetColor (hps, CLR_BLACK);    break;
  109.           case xxRed:        GpiSetColor (hps, CLR_RED);    break;
  110.           case xxGreen:        GpiSetColor (hps, CLR_GREEN);    break;
  111.           case xxBlue:        GpiSetColor (hps, CLR_BLUE);    break;
  112.           case xxCyan:        GpiSetColor (hps, CLR_CYAN);    break;
  113.           case xxMagenta:    GpiSetColor (hps, CLR_PINK);    break;
  114.           case xxYellow:    GpiSetColor (hps, CLR_YELLOW);    break;
  115.         }
  116.         ptl.x = x;
  117.         GpiSetPel (hps, &ptl);
  118.     }
  119.   }
  120.   WinEndPaint(hps);
  121. };
  122.  
  123.  
  124.  
  125. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  126. {
  127.   switch(msg){
  128.     case WM_SIZE:
  129.       WinInvalidateRect(hwnd, NULL, FALSE); 
  130.       return 0;
  131.  
  132.     case WM_PAINT:
  133.       repaint (hwnd);
  134.       return 0;
  135.  
  136.     case WM_CHAR:
  137.       if(!(CHARMSG(&msg)->fs &KC_KEYUP))
  138.          return 0;
  139.  
  140.       switch((CHARMSG(&msg)->chr)%256)
  141.       {
  142.           case   /*1*256+*/ 27 /* esc  */:
  143.             WinInvalidateRect(hwnd,NULL,FALSE);
  144.             return 0;
  145.  
  146.           case /* 28*256+*/13 /* Ent1 */:
  147.             DosBeep(1000,300);
  148.             return 0;
  149.       };
  150.       return 0;
  151.  
  152.     case WM_BUTTON1DOWN:
  153.     case WM_BUTTON2DOWN:
  154.     case WM_BUTTON3DOWN:
  155.       break;
  156.   }
  157.   return WinDefWindowProc(hwnd, msg, mp1, mp2);
  158. }
  159.  
  160.  
  161.  
  162.  
  163. CHAR szClientClass[]="HP2xx";
  164. static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
  165.                 FCF_BORDER        | FCF_MINBUTTON|
  166.                 FCF_SHELLPOSITION | FCF_TASKLIST |
  167.                 FCF_NOBYTEALIGN;
  168.  
  169.  
  170.  
  171. void    win_close()
  172. {
  173.   WinDestroyWindow   (hwndFrame);
  174.   WinDestroyMsgQueue (hmq);
  175.   WinTerminate         (hab);
  176. }
  177.  
  178.  
  179.  
  180. int    win_open (int x, int y, int w, int h)
  181. {
  182. int     cx_frame, cy_frame;
  183. HPOINTER WinQuerySysPointer(HWND, SHORT, BOOL);
  184.  
  185.   hab = WinInitialize(0);
  186.   hmq = WinCreateMsgQueue(hab, 0);
  187.  
  188.   WinRegisterClass(hab, szClientClass, (PFNWP) ClientWndProc, 0L, 0);
  189.  
  190.   hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  191.                                  WS_VISIBLE | WS_MAXIMIZED,
  192.                                  (ULONG far *) &flFrameFlags,
  193.                                  szClientClass, NULL, 0L,
  194.                                  (HMODULE) NULL, 0, &hwndClient);
  195.  
  196.   scr_width    = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  197.   scr_height    = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  198.  
  199.   cx_frame    =   WinQuerySysValue (HWND_DESKTOP, SV_CXBORDER)  << 1;
  200.   cy_frame    = ( WinQuerySysValue (HWND_DESKTOP, SV_CYBORDER)  << 1 ) +
  201.             WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  202.  
  203.   if (x+w+cx_frame > scr_width || y+h+cy_frame > scr_height)
  204.   {
  205.     win_close();
  206.     fprintf( stderr, "Window exceeds screen limits !\n" );
  207.     return ERROR;
  208.   }
  209.  
  210.   WinSetWindowPos(hwndFrame, HWND_TOP, 
  211.         x - WinQuerySysValue (HWND_DESKTOP, SV_CXBORDER) + 1,
  212.         scr_height - h - y - cy_frame, 
  213.         w + cx_frame, h + cy_frame,
  214.                 SWP_MOVE | SWP_SIZE | SWP_ACTIVATE | SWP_SHOW);
  215.  
  216.   WinSendMsg(hwndFrame, WM_SETICON,
  217.              WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE),
  218.              NULL);
  219.   return 0;
  220. }
  221.  
  222.  
  223.  
  224. void    PicBuf_to_PM (PicBuf *picbuf, PAR *p)
  225. {
  226.   if (!p->quiet)
  227.   {
  228.     fprintf(stderr, "\nPM preview follows.\n");
  229.     fprintf(stderr, "Close window to end graphics mode\n");
  230.   }
  231.  
  232.   pbuf = picbuf;
  233.  
  234.   if (win_open( (int)(p->xoff * p->dpi_x / 25.4),
  235.         (int)(p->yoff * p->dpi_y / 25.4),
  236.         picbuf->nb << 3, picbuf->nr ) )
  237.     return;
  238.  
  239.   while(WinGetMsg(hab, (QMSG far *) &qmsg, NULL, 0, 0))
  240.     WinDispatchMsg(hab, (QMSG far *) &qmsg);
  241.  
  242.   win_close();
  243. }
  244.  
  245.