"Fossies" - the Fresh Open Source Software Archive

Member "hp2xx-3.4.4/sources/to_pm.c" (21 Jun 2003, 7034 Bytes) of package /linux/misc/old/hp2xx-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "to_pm.c" see the Fossies "Dox" file reference documentation.

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