Пример #1
0
/*@ XPrinterDevice::OpenPrinterJob(char *pszJobTitle)
@remarks Open a printer job
@parameters char * title      title of the printer job
@returns BOOL success
*/
BOOL XPrinterDevice::OpenPrinterJob(const char *pszJobTitle)
{
   hdc = DevOpenDC(pSetup->hab, pSetup->lDCType, (PSZ) "*", 9, pSetup->pDevOpenData, (HDC) 0);

   if (hdc == NULLHANDLE)
      return FALSE;

   SIZEL sizel;

   sizel.cx = 0;
   sizel.cy = 0;
   hps = GpiCreatePS(pSetup->hab, hdc, &sizel, pSetup->lWorldCoordinates | GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC);

   if (GPI_ERROR == hps)
   {
      DevCloseDC(hdc);
      hdc = (HDC) 0;
      hps = (HPS) 0;
      return FALSE;
   }
   DevEscape(hdc, DEVESC_STARTDOC, strlen(pszJobTitle), (PSZ) pszJobTitle, NULL, NULL);
   if (!GpiSetCharMode(hps, CM_MODE2))
      return FALSE;
   if (!GpiSetTextAlignment(hps, TA_NORMAL_HORIZ, TA_NORMAL_VERT))
      return FALSE;

   SIZEL sizPage;

   if (!GpiQueryPS(hps, &sizPage))
      return FALSE;
   width = sizPage.cx;
   height = sizPage.cy;

   return TRUE;
}
Пример #2
0
void qt_free_mem_ps(HPS hps)
{
    HDC hdc = GpiQueryDevice(hps);
    GpiAssociate(hps, NULLHANDLE);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);
}
Пример #3
0
 static int loadAlternativeIconTable(SKINDATA *wnd)
 {
    SIZEL              sizl            = { 0, 0 };  /* use same page size as device */
    DEVOPENSTRUC       dop             = { 0, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
    HAB                hab             = icqQueryAnchorBlock(wnd->icq);
    HDC                hdc;
    HPS                hps;

    CHKPoint();

    icqskin_deleteImage( wnd->iconImage );
    icqskin_deleteImage( wnd->iconMasc  );

    hdc  = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    hps  = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

    if(hps)
    {
       wnd->iconImage = GpiLoadBitmap(hps, module, 101, ICONBAR_ROWS * PWICQICONBARSIZE, ICONBAR_ROWS);
       wnd->iconMasc  = GpiLoadBitmap(hps, module, 102, ICONBAR_ROWS * PWICQICONBARSIZE, ICONBAR_ROWS);
       GpiDestroyPS(hps);
    }

    DevCloseDC(hdc);

    return ICONBAR_ROWS;
 }
Пример #4
0
void XPrinterDevice::CleanupPrinter()
{
   if (pSetup->hpsPrinterInfo)
   {
      GpiAssociate(pSetup->hpsPrinterInfo, (HDC) 0);
      GpiDestroyPS(pSetup->hpsPrinterInfo);
      pSetup->hpsPrinterInfo = (HPS) 0;
   }

   if (pSetup->hdcPrinterInfo)
   {
      DevCloseDC(pSetup->hdcPrinterInfo);
      pSetup->hdcPrinterInfo = (HDC) 0;
   }

   if (pSetup->pQueueInfo)
   {
      free(pSetup->pQueueInfo);
      pSetup->pQueueInfo = NULL;
   }

   if (pSetup->pDriverData)
   {
      free(pSetup->pDriverData);
      pSetup->pDriverData = NULL;
   }

   if (pSetup->devopenstruc.pszDriverName)
   {
      free(pSetup->devopenstruc.pszDriverName);
      pSetup->devopenstruc.pszDriverName = NULL;
   }
}
Пример #5
0
gfxOS2Surface::~gfxOS2Surface()
{
#ifdef DEBUG_thebes_2
    printf("gfxOS2Surface[%#x]::~gfxOS2Surface()\n", (unsigned int)this);
#endif

    // Surfaces connected to a window were created using WinGetPS so we should
    // release it again with WinReleasePS. Memory or printer surfaces on the
    // other hand were created on device contexts with the GPI functions, so
    // use those to clean up stuff.
    if (mWnd) {
        if (mPS) {
            WinReleasePS(mPS);
        }
    } else {
        if (mBitmap) {
            GpiSetBitmap(mPS, nullptr);
            GpiDeleteBitmap(mBitmap);
        }
        if (mPS) {
            GpiDestroyPS(mPS);
        }
        if (mDC) {
            DevCloseDC(mDC);
        }
    }
}
Пример #6
0
gfxOS2Surface::~gfxOS2Surface()
{
    switch (mSurfType) {

        case os2Window:
            if (mPS)
                WinReleasePS(mPS);
            break;

        case os2Print:
            printf("~gfxOS2Surface for print - DC= %lx PS= %lx w= %d h= %d\n",
                   mDC, mPS, mSize.width, mSize.height);

            if (mPS)
                GpiDestroyPS(mPS);
            if (mDC)
                DevCloseDC(mDC);

        case os2Image:
        default:
            break;
     }

    RecordMemoryFreed();
}
Пример #7
0
nsresult nsDeviceContextSpecOS2::SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, ULONG printer)
{
  if (aPrintSettings == nsnull)
    return NS_ERROR_FAILURE;

  int bufferSize = 3 * sizeof(DJP_ITEM);
  PBYTE pDJP_Buffer = new BYTE[bufferSize];
  memset(pDJP_Buffer, 0, bufferSize);
  PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer;

  HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer);

  //Get Number of Copies from Job Properties
  pDJP->lType = DJP_CURRENT;
  pDJP->cb = sizeof(DJP_ITEM);
  pDJP->ulNumReturned = 1;
  pDJP->ulProperty = DJP_SJ_COPIES;
  pDJP->ulValue = 1;
  pDJP++;

  //Get Orientation from Job Properties
  pDJP->lType = DJP_CURRENT;
  pDJP->cb = sizeof(DJP_ITEM);
  pDJP->ulNumReturned = 1;
  pDJP->ulProperty = DJP_SJ_ORIENTATION;
  pDJP->ulValue = 1;
  pDJP++;

  pDJP->lType = DJP_NONE;
  pDJP->cb = sizeof(DJP_ITEM);
  pDJP->ulNumReturned = 1;
  pDJP->ulProperty = 0;
  pDJP->ulValue = 0;

  LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer);
  LONG rc = GreEscape(hdc, DEVESC_QUERYJOBPROPERTIES, bufferSize, pDJP_Buffer, 
                      &driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer)));

  pDJP = (PDJP_ITEM) pDJP_Buffer;
  if ((rc == DEV_OK) || (rc == DEV_WARNING)) { 
    while (pDJP->lType != DJP_NONE) {
      if ((pDJP->ulProperty == DJP_SJ_ORIENTATION) && (pDJP->lType > 0)){
        if ((pDJP->ulValue == DJP_ORI_PORTRAIT) || (pDJP->ulValue == DJP_ORI_REV_PORTRAIT))
          aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
        else
         aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
      }
      if ((pDJP->ulProperty == DJP_SJ_COPIES) && (pDJP->lType > 0)){
        aPrintSettings->SetNumCopies(PRInt32(pDJP->ulValue));
      }
      pDJP = DJP_NEXT_STRUCTP(pDJP);
    }
  }
  
  delete [] pDJP_Buffer;
  DevCloseDC(hdc);  
  return NS_OK;
}
Пример #8
0
XBitmap :: ~XBitmap()
{
   GpiDeleteBitmap(hbm);
   GpiDestroyPS(hps);
   DevCloseDC(hdc);
   hbm = 0;
   hps = 0;
   hdc = 0;
}
Пример #9
0
void new_display( void )
{
#ifdef DRAW_ALL_AT_ONCE
    GpiSetBitmap( Mem_dc, Old_bitmap );
    GpiDeleteBitmap( Draw_bitmap );
    Draw_bitmap = NULLHANDLE;
    GpiDestroyPS( Mem_dc );
    DevCloseDC( Hdc );
#endif
}
Пример #10
0
VOID DestroyPS()
{
    HBITMAP hbm;
    
    hbm = GpiSetBitmap (hpsBufferGlob, NULLHANDLE);
    
    if (hbm != NULLHANDLE)
	GpiDeleteBitmap (hbm);
    
    GpiDestroyPS (hpsBufferGlob);
    DevCloseDC (hdcBufferGlob);
}
/****************************************************************\
 *
 *--------------------------------------------------------------
 *
 *  Name:ClkDestroy()
 *
 *  Purpose: Destroy clock face.
 *
 *
 *
 *  Usage:
 *
 *  Method:
 *          -
 *
 *          -
 *          -
 *
 *          -
 *          -
 *
 *  Returns:VOID
 *
 *
\****************************************************************/
VOID ClkDestroy (HWND hwnd)
{
    HBITMAP hbm;

    hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE);

    if (hbm != NULLHANDLE)
        GpiDeleteBitmap (hbm);

    GpiDestroyPS (hpsBuffer);
    DevCloseDC (hdcBuffer);
}
Пример #12
0
/* Close the os2prn driver */
static int
os2prn_close(gx_device * dev)
{
    int code;
    LONG lOut;
    USHORT usJobID;

    /* tell printer that all is finished */
    DevEscape(opdev->hdc, DEVESC_ENDDOC, 0L, NULL, &lOut, (PBYTE) & usJobID);
    /* Free resources */
    GpiAssociate(opdev->hps, (HDC) NULL);
    GpiDestroyPS(opdev->hps);
    DevCloseDC(opdev->hdc);

    if (opdev->hpsMem != GPI_ERROR)
	GpiDestroyPS(opdev->hpsMem);
    if (opdev->hdcMem != DEV_ERROR)
	DevCloseDC(opdev->hdcMem);

    code = gdev_prn_close(dev);
    /* delete unwanted temporary file */
    unlink(opdev->fname);
    return code;
}
Пример #13
0
void SetupDevModeFromSettings(ULONG printer, nsIPrintSettings* aPrintSettings)
{
  if (aPrintSettings) {
    int bufferSize = 3 * sizeof(DJP_ITEM);
    PBYTE pDJP_Buffer = new BYTE[bufferSize];
    memset(pDJP_Buffer, 0, bufferSize);
    PDJP_ITEM pDJP = (PDJP_ITEM) pDJP_Buffer;

    HDC hdc = nsDeviceContextSpecOS2::PrnDlg.GetDCHandle(printer);
    char* driver = nsDeviceContextSpecOS2::PrnDlg.GetDriverType(printer);

    // Setup Orientation
    PRInt32 orientation;
    aPrintSettings->GetOrientation(&orientation);
    if (!strcmp(driver, "LASERJET"))
      pDJP->lType = DJP_ALL;
    else
      pDJP->lType = DJP_CURRENT;
    pDJP->cb = sizeof(DJP_ITEM);
    pDJP->ulNumReturned = 1;
    pDJP->ulProperty = DJP_SJ_ORIENTATION;
    pDJP->ulValue = orientation == nsIPrintSettings::kPortraitOrientation?DJP_ORI_PORTRAIT:DJP_ORI_LANDSCAPE;
    pDJP++;

    // Setup Number of Copies
    PRInt32 copies;
    aPrintSettings->GetNumCopies(&copies);
    pDJP->cb = sizeof(DJP_ITEM);
    pDJP->lType = DJP_CURRENT;
    pDJP->ulNumReturned = 1;
    pDJP->ulProperty = DJP_SJ_COPIES;
    pDJP->ulValue = copies;
    pDJP++;

    pDJP->cb = sizeof(DJP_ITEM);
    pDJP->lType = DJP_NONE;
    pDJP->ulNumReturned = 1;
    pDJP->ulProperty = 0;
    pDJP->ulValue = 0;

    LONG driverSize = nsDeviceContextSpecOS2::PrnDlg.GetPrintDriverSize(printer);
    GreEscape (hdc, DEVESC_SETJOBPROPERTIES, bufferSize, pDJP_Buffer, 
               &driverSize, PBYTE(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(printer)));

    delete [] pDJP_Buffer;
    DevCloseDC(hdc);
  }
}
Пример #14
0
// tiles an image across preview window
BOOL DrawImage(PSPAINT * pPaint, HBITMAP hbm, short sState, PLUGINSHARE* pPluginData)
{
    SIZEL slHps;
    POINTL aptl[4];
    HDC hdc;
    HPS hps;
    HAB hab = WinQueryAnchorBlock(pPaint->hwnd);


    // setup source bitmap
    hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);

    // create source hps
    slHps.cx = pPluginData->ulCx/2;
    slHps.cy = pPluginData->ulCy/5;
    hps = GpiCreatePS(hab,
                      hdc,
                      &slHps,
                      PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

    // set bmp into hps
    GpiSetBitmap(hps, hbm);

    // initial blt location
    aptl[0].x = pPaint->rectlWindow.xLeft;
    //aptl[0].y = pPaint->rectlWindow.yBottom;
    aptl[0].y = pPaint->rectlWindow.yBottom-1;
    aptl[1].x = pPaint->rectlWindow.xRight;
    //aptl[1].y = pPaint->rectlWindow.yTop;
    aptl[1].y = pPaint->rectlWindow.yTop-1;
    aptl[2].x = 0;
    aptl[2].y = 0;
    aptl[3].x = slHps.cx;
    aptl[3].y = slHps.cy;
     // blt
     GpiBitBlt(pPaint->hps, hps, 4L, aptl, ROP_SRCCOPY, BBO_IGNORE);

    // clean up
    GpiSetBitmap(hps, NULLHANDLE);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);

    return (TRUE);


}
Пример #15
0
/*@ XPrinterDevice::KillPrinterJob()
@remarks Remove the printer job from the printer queue.
*/
void XPrinterDevice::KillPrinterJob()
{
   DevEscape(hdc, DEVESC_ABORTDOC, 0, NULL, NULL, NULL);

   if (hps)
   {
      GpiSetCharSet(hps, 0);
      GpiAssociate(hps, (HDC) 0);
      GpiDestroyPS(hps);
      hps = (HPS) 0;
   }

   if (hdc)
   {
      DevCloseDC(hdc);
      hdc = (HDC) 0;
   }
}
Пример #16
0
void
gfxOS2Platform::InitDisplayCaps()
{
    // create DC compatible with the screen
    HDC dc = DevOpenDC((HAB)1, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
    if (dc > 0) {
        // we do have a DC and we can query the DPI setting from it
        LONG lDPI;
        if (DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &lDPI))
            gfxPlatform::sDPI = lDPI;
        DevCloseDC(dc);
    }

    if (gfxPlatform::sDPI <= 0) {
        // Fall back to something sane
        gfxPlatform::sDPI = 96;
    }
}
Пример #17
0
//----------------------------------------------------------------------------
// NPP_DestroyStream:
//----------------------------------------------------------------------------
NPError NP_LOADDS
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason) {
  if ( instance == 0 ) return NPERR_INVALID_INSTANCE_ERROR;
  PluginInstance* This = (PluginInstance*) instance->pdata;

  if ( reason == NPRES_DONE && This->bufMeta ) {
    // create metafile from buffer

    // 1-st, create empty metafile
    HAB hab=WinQueryAnchorBlock( This->hWnd );
    DEVOPENSTRUC dop;
    dop.pszLogAddress = (PSZ) NULL;
    dop.pszDriverName = "DISPLAY";
    HDC hdcMeta = DevOpenDC( hab,
        OD_METAFILE,                 /* Metafile device context             */
        "*",                         /* Ignores OS2.INI                     */
        2L,                          /* Uses first two fields               */
        (PDEVOPENDATA) &dop,         /* Device information                  */
        (HDC) NULLHANDLE );          /* Compatible device context           */
    SIZEL sizlPage={ 0, 0 };
    HPS hpsMeta = GpiCreatePS( hab, hdcMeta, &sizlPage, PU_PELS | GPIA_ASSOC );
    GpiAssociate( hpsMeta, (HDC)NULLHANDLE );
    HMF hmf = DevCloseDC( hdcMeta );
    GpiDestroyPS( hpsMeta );

    // 2-nd, add real data
    GpiSetMetaFileBits( hmf, 0, This->offMeta, This->bufMeta );
    SelectMetaFile( This, hmf );
  }
  // delete buffer
  if ( This->bufMeta ) {
    free( This->bufMeta );
    This->bufMeta=NULL;
    This->cbMeta=0;
    This->offMeta=0;
  }
  return NPERR_NO_ERROR;
}
Пример #18
0
HBITMAP EXPENTRY sknLoadBitmap( HWND hwnd, PSZ pszFileName )
{
   HBITMAP         ret             = 0;

   SIZEL           sizl            = { 0, 0 };  /* use same page size as device */
   DEVOPENSTRUC    dop             = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
   HAB             hab             = WinQueryAnchorBlock(hwnd);
   HDC             hdc;
   HPS             hps;

   hdc  = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
   hps  = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

   if(hps)
   {
      ret = LoadBitmap(hab,hdc,hps,pszFileName);
      GpiDestroyPS(hps);
   }

   DevCloseDC(hdc);

   return ret;
}
Пример #19
0
VOID PMfrWriteClipbrdBmp(HAB hab)
   {

   HDC hdcClip;         /* memory DC and PS to extract from the clipboard */
   HPS hpsClip;
   HBITMAP hbmClip;
   SIZEL sizl;
   BITMAPINFOHEADER bmp;
   ULONG _far *alRGBColors;
   LONG errorcode;
   char _far *fp1;
   char _far *fp2;
   int i;

   if (WinOpenClipbrd(hab))
      {
      /* get the memory DC and PS to copy the bitmap */
      hdcClip = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;

      sizl.cx = cp.cx; sizl.cy = cp.cy;

      hpsClip = GpiCreatePS (hab, hdcClip, &sizl,
                   PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

      bmp.cbFix   = sizeof bmp;
      bmp.cx      = cp.cx;
      bmp.cy      = cp.cy;
      bmp.cPlanes = cp.cPlanes;
      bmp.cBitCount = cp.cBitCount;
      hbmClip = GpiCreateBitmap (hpsClip, &bmp, 0L, NULL, NULL);

      GpiSetBitmap(hpsClip, hbmClip);

      /* initialize and black out the bitmap */
      alRGBColors = (ULONG _far *) _fmalloc(sizeof(ULONG) * cp.colors);
      /* beginning of source array */
      fp2 = (char _far *) &cp.pbmiMemory->argbColor[0];
      /* beginning of dest array */
      fp1 = (char _far *) &alRGBColors[0];
      for (i = 0; i < cp.colors; i++)
          {   /* copy base bytes for number of screen colors */
          alRGBColors[i] = 0;
          _fmemcpy(fp1, fp2, sizeof(RGB) );
          fp1 += sizeof(ULONG);
          fp2 += sizeof(RGB);
          }

      GpiSetMix ( hpsClip, FM_OVERPAINT) ;
      GpiSetBackMix (hpsClip, BM_LEAVEALONE) ;
      GpiCreateLogColorTable(hpsClip, LCOL_RESET | LCOL_REALIZABLE,
              LCOLF_CONSECRGB, 0L, cp.colors, alRGBColors);

      /* now copy the bits */
      cp.pbmiMemory->cx = cp.cx;
      cp.pbmiMemory->cy = cp.cy;
      cp.pbmiMemory->cPlanes = cp.cPlanes;
      cp.pbmiMemory->cBitCount = cp.cBitCount;
      errorcode = GpiSetBitmapBits(hpsClip, 0L, (LONG) cp.cy,
                                cp.pixels, cp.pbmiMemory);

      /* unlink the new bitmap */
      GpiSetBitmap(hpsClip, (HBITMAP) NULL);

      /* write to the clipboard */
      WinEmptyClipbrd (hab);
      WinSetClipbrdData (hab, (ULONG) hbmClip, CF_BITMAP, CFI_HANDLE);

      /* now clean up */

      _ffree(alRGBColors);
      GpiDestroyPS(hpsClip);
      DevCloseDC(hdcClip);

      WinCloseClipbrd(hab);
      }

   }
Пример #20
0
// *******************************************************************************
// FUNCTION:     GetBitmapFromTrack
//
// FUNCTION USE: Creates a bitmap from a rectangle structure
//
// DESCRIPTION:  This function takes the rectangle structure that is created 
//               as a result of the tracking operation and creates a bitmap 
//               of that area.  
//
// PARAMETERS:   RECTL    tracking rectangle
//
// RETURNS:      HBITMAP  bitmap handle
//
// INTERNALS:    NONE
//
// HISTORY:
//
// *******************************************************************************
HBITMAP GetBitmapFromTrack (RECTL rclTrack)
{
 HAB                hab;                           
 HBITMAP            hbmTrack;
 HDC                hdcMemory;
 HPS                hpsMemory;
 HPS                hpsScreen;
 LONG               lFormats[2];
 POINTL             aptl[3];
 SIZEL              sizl;
 BITMAPINFOHEADER2  bmp2;

 // --------------------------------------------------------------------------                    
 // Get an anchor block handle                                                                    
 // --------------------------------------------------------------------------                    
 hab = WinQueryAnchorBlock(HWND_DESKTOP);

 // --------------------------------------------------------------------------                    
 // Get a memory device context                                                                  
 // --------------------------------------------------------------------------                    
 hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE) ;

 // --------------------------------------------------------------------------                    
 // Set presentation space size                                                                
 // --------------------------------------------------------------------------                    
 sizl.cx = sizl.cy = 0 ;

 // --------------------------------------------------------------------------                             
 // Create a micro presentation space and associate it                                                                           
 // --------------------------------------------------------------------------                             
 hpsMemory = GpiCreatePS (hab,
                          hdcMemory,
                          &sizl,
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

 // --------------------------------------------------------------------------           
 // Call GpiQueryDeviceBitmapFormats to get the number of bit planes                                   
 // --------------------------------------------------------------------------           
 GpiQueryDeviceBitmapFormats (hpsMemory,
                              2L,
                              lFormats);

 // --------------------------------------------------------------------------        
 // Initialize the bitmap info header structure                 
 // --------------------------------------------------------------------------        
 memset(&bmp2, 0, sizeof(BITMAPINFOHEADER2));

 // --------------------------------------------------------------------------                     
 // Populate the bitmap info header structure                                                    
 // --------------------------------------------------------------------------                     
 bmp2.cbFix     = sizeof bmp2;
 bmp2.cx        = (rclTrack.xRight - rclTrack.xLeft);
 bmp2.cy        = (rclTrack.yTop   - rclTrack.yBottom);
 bmp2.cPlanes   = lFormats[0];
 bmp2.cBitCount = lFormats[1];

 // --------------------------------------------------------------------------         
 // Create a bitmap representing the tracking rectangle                                
 // --------------------------------------------------------------------------         
 hbmTrack = GpiCreateBitmap (hpsMemory, &bmp2, 0L, NULL, NULL);

 if (hbmTrack == GPI_ERROR)
  {
   return GPI_ERROR;
  }

 else
  {
   // --------------------------------------------------------------------------        
   // Set the bitmap into our memory presentation space.                                                                      
   // --------------------------------------------------------------------------        
   GpiSetBitmap (hpsMemory, hbmTrack);
   hpsScreen = WinGetScreenPS (HWND_DESKTOP);
  
   aptl[0].x = 0;
   aptl[0].y = 0;
   aptl[1].x = bmp2.cx;
   aptl[1].y = bmp2.cy;
   aptl[2].x = rclTrack.xLeft;
   aptl[2].y = rclTrack.yBottom;
  
   WinLockVisRegions (HWND_DESKTOP, TRUE);
  
   // --------------------------------------------------------------------------                 
   // Bit blit the contents of the source presentation space into our target                     
   // presentation space.  This is how we copy the bitmap from the source to                     
   // the target.                                                                                
   // --------------------------------------------------------------------------                 
   GpiBitBlt (hpsMemory,      //  Target presentation space handle           
              hpsScreen,      //  Source presentation space handle           
              3L,             //  Number of Points                           
              aptl,           //  Array of Points                            
              ROP_SRCCOPY,    //  Mixing function (source copy)              
              BBO_IGNORE);    //  Options                                    
  
   WinLockVisRegions (HWND_DESKTOP, FALSE);
   WinReleasePS (hpsScreen);
  }

 // --------------------------------------------------------------------------                  
 // Free Graphics Engine Resources 
 // --------------------------------------------------------------------------                  
 GpiDestroyPS (hpsMemory);
 DevCloseDC (hdcMemory);

 // --------------------------------------------------------------------------                  
 // Return bitmap handle           
 // --------------------------------------------------------------------------                  
 return hbmTrack;
}
BOOL CandyBarZFrameBorderPaintProc(HWND hwnd, RECTL * rect, HPS hpsFrame, short sState)
{
    CBZDATA     *pCBZData;
    CBZSHARE    *pCBZShare;
    PSPAINT     *pPaint;
    TEMPPAINT   *pFramePaint;
    BOOL        rc;
    int         i;
    ULONG       ulDataOffset;

    if (DosGetNamedSharedMem((PPVOID) & pCBZShare, CBZ_SHARE,  PAG_READ) != NO_ERROR)
    {
        return (FALSE);
    }
    ulDataOffset = pCBZShare->ulDataOffset;
    DosFreeMem(pCBZShare);

    // get window data
    if ((pCBZData = WinQueryWindowPtr(CandyBarZGetTopLevelFrameHWND(hwnd), ulDataOffset)) == NULL
            || !pCBZData->bFrameBorderEnabled  )
    {
        return (FALSE);
    }

    if (pCBZData->sFrameBorderIndex >= pCBZData->sPushButtonIndex)
    {
        return (FALSE);
    }

    // alloc paint struct
    if (DosAllocMem((PPVOID) & pFramePaint,
                    sizeof(TEMPPAINT),
                    PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        return (FALSE);
    }
    memset(pFramePaint, 0, sizeof(TEMPPAINT));

    pFramePaint->hab = WinQueryAnchorBlock(hwnd);

    // alloc paint struct
    if (DosAllocMem((PPVOID) & pPaint,
                    sizeof(PSPAINT),
                    PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    memset(pPaint, 0, sizeof(PSPAINT));

    //Text plugin needs this for quering presentation parameters.
    pPaint->hwnd = hwnd;

    // entire window
    pPaint->rectlWindow = pPaint->rectlUpdate = *rect;

    // get PS
    pPaint->hpsWin = hpsFrame;

    // we will blt and draw gradient text into the hps associated with this dc
    if ((pFramePaint->hdc = DevOpenDC(pFramePaint->hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE))
            == NULLHANDLE)
    {
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    // create hps2 for hdc2.  hps for hdc depends on size of bitmap, so it's not created until
    // we know if it's active or not.  create for size of window, then we blt only portion
    // needed
    pFramePaint->slHPS.cx = pPaint->rectlWindow.xRight;
    pFramePaint->slHPS.cy = pPaint->rectlWindow.yTop;

    if ((pPaint->hps = GpiCreatePS(pFramePaint->hab,
                                   pFramePaint->hdc,
                                   &(pFramePaint->slHPS),
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC))
            == NULLHANDLE)
    {
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }

    pFramePaint->bif2.cbFix = sizeof(BITMAPINFOHEADER2);
    pFramePaint->bif2.cx = pPaint->rectlWindow.xRight;
    pFramePaint->bif2.cy = pPaint->rectlWindow.yTop;
    pFramePaint->bif2.cBitCount = 24;
    pFramePaint->bif2.cPlanes = 1;
    if ((pFramePaint->hbmTemp = GpiCreateBitmap(pPaint->hps,  // create bitmap
                                 (PBITMAPINFOHEADER2) & (pFramePaint->bif2),
                                                (ULONG) 0,
                                                (PSZ) NULL,
                       (PBITMAPINFO2) & (pFramePaint->bif2))) == NULLHANDLE)
    {
        GpiDestroyPS(pPaint->hps);
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }
    if (GpiSetBitmap(pPaint->hps, pFramePaint->hbmTemp) == HBM_ERROR)
    {
        GpiDeleteBitmap(pFramePaint->hbmTemp);
        GpiDestroyPS(pPaint->hps);
        DevCloseDC(pFramePaint->hdc);
        DosFreeMem(pPaint);
        DosFreeMem(pFramePaint);
        return (FALSE);
    }

    // set color table into rgb mode.  otherwise colors between 0 and
    // 15 are interpreted as indexes
    GpiCreateLogColorTable(pPaint->hps, 0, LCOLF_RGB, 0, 0, NULL);

    {
        //fill ps with default bg color...
        ULONG attrFound;
        long lColor;
        if ( (WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &attrFound, sizeof(attrFound),
                                                &lColor, QPF_PURERGBCOLOR)) == 0 )
           lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0);
        // fill with default color
        WinFillRect(pPaint->hps, &(pPaint->rectlUpdate), lColor);
    }

    // call Plugins Paint Procedures here
    for (i = pCBZData->sFrameBorderIndex; i < pCBZData->sPushButtonIndex; i++)
    {
        if ( !(pCBZData->Plugins[i].pfnPluginRender(pPaint, pCBZData->Plugins[i].pData, sState)) )
        {
            GpiSetBitmap(pPaint->hps, NULLHANDLE);
            GpiDeleteBitmap(pFramePaint->hbmTemp);
            GpiDestroyPS(pPaint->hps);
            DevCloseDC(pFramePaint->hdc);
            DosFreeMem(pPaint);
            DosFreeMem(pFramePaint);
            return (FALSE);
        }
    }


    if ((rc = BltToWindow(pPaint)) == TRUE)
    {
        //paint sucessful, validate the window
//        WinQueryWindowRect(hwnd, &(pPaint->rectlUpdate));
        WinValidateRect(hwnd, &(pPaint->rectlUpdate), FALSE);
    }
    GpiSetBitmap(pPaint->hps, NULLHANDLE);
    GpiDeleteBitmap(pFramePaint->hbmTemp);
    GpiDestroyPS(pPaint->hps);
    DevCloseDC(pFramePaint->hdc);
    DosFreeMem(pPaint);
    DosFreeMem(pFramePaint);

    return (rc);
}
Пример #22
0
 HBITMAP icqskin_createFrameBackground(HWND hwnd, HBITMAP bg, short cx, short cy, HBITMAP *img, HBITMAP *msk)
 {
#ifndef SKINNED_GUI
    return NO_IMAGE;
#else
    SIZEL                sizl    = { 0, 0 };
    DEVOPENSTRUC         dop     = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
    HAB                  hab     = WinQueryAnchorBlock(hwnd);
    HPS                  hps;
    HDC                  hdc;
    BITMAPINFOHEADER     bmpData;
    BITMAPINFOHEADER2    bmih;
    RECTL                rcl;
    int					 x;
    int                  y;
    int                  f;

    icqskin_deleteImage(bg);


    for(f=0;f<ICQFRAME_SKINBITMAPS && img[f] == NO_IMAGE;f++);

    if(f >= ICQFRAME_SKINBITMAPS)
       return NO_IMAGE;

    hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = cx;
    bmih.cy           = cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;
    bg                = GpiCreateBitmap(hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,bg);

    /* Clear background */
    rcl.xLeft   =
    rcl.yBottom = 0;
    rcl.xRight  = cx;

    rcl.yTop    = cy;

    DBGTrace(cx);
    DBGTrace(cy);

    icqskin_paintBackground(hwnd,hps,&rcl);

    GpiSelectPalette(hps,NULLHANDLE);
    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    /* Stretch images */
    y = cy;

    if(img[ICQFRAME_MIDSTRETCH] != NO_IMAGE)
    {
       if(img[ICQFRAME_TITLESTRETCH] != NO_IMAGE)
       {
          GpiQueryBitmapParameters(img[ICQFRAME_TITLESTRETCH], &bmpData);
          y -= bmpData.cy;
       }

       if(img[ICQFRAME_MIDLEFT] == NO_IMAGE)
       {
          x = 0;
       }
       else
       {
          GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
          x = bmpData.cx;
       }

       GpiQueryBitmapParameters(img[ICQFRAME_MIDSTRETCH], &bmpData);
       y -= bmpData.cy;

       do
       {
          for(f=x;f<cx;f+=bmpData.cx)
             drawFrameBG(img,msk, ICQFRAME_MIDSTRETCH, hps, f, y, bmpData.cx, bmpData.cy);
          y -= bmpData.cy;
       } while(y > 0);

    }

    if(img[ICQFRAME_TITLESTRETCH] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLESTRETCH], &bmpData);
       y = cy-bmpData.cy;
       for(x=0; x<cx; x += bmpData.cx)
          drawFrameBG(img,msk, ICQFRAME_TITLESTRETCH, hps, x, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_MIDLEFT, hps, 0, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDRIGHT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_MIDRIGHT, hps, cx-bmpData.cx, 0, bmpData.cx, bmpData.cy);
    }

    y = cy;
    if(img[ICQFRAME_TITLELEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLELEFT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TITLELEFT, hps, 0, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_TOPLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TOPLEFT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TOPLEFT, hps, 0, y, bmpData.cx, bmpData.cy);
    }


    if(img[ICQFRAME_MIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDLEFT], &bmpData);
       while(y > 0)
       {
          y -= bmpData.cy;
          drawFrameBG(img,msk, ICQFRAME_MIDLEFT, hps, 0, y, bmpData.cx, bmpData.cy);
       }
    }

    // Right images
    y = cy;

    if(img[ICQFRAME_TITLERIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TITLERIGHT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TITLERIGHT, hps, cx-bmpData.cx, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_TOPRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_TOPRIGHT], &bmpData);
       y -= bmpData.cy;
       drawFrameBG(img,msk, ICQFRAME_TOPRIGHT, hps, cx-bmpData.cx, y, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_MIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_MIDRIGHT], &bmpData);
       x = cx-bmpData.cx;
       while(y > 0)
       {
          y -= bmpData.cy;
          drawFrameBG(img,msk, ICQFRAME_MIDRIGHT, hps, x, y, bmpData.cx, bmpData.cy);
       }
    }

    // Bottom images
    if(img[ICQFRAME_BOTTOMSTRETCH] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMSTRETCH], &bmpData);
       for(x=0; x<cx; x += bmpData.cx)
          drawFrameBG(img,msk, ICQFRAME_BOTTOMSTRETCH, hps, x, 0, bmpData.cx, bmpData.cy);

    }

    x = 0;
    if(img[ICQFRAME_BOTTOMLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMLEFT], &bmpData);
       x += bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMLEFT, hps, 0, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_BOTTOMMIDLEFT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMMIDLEFT], &bmpData);
       drawFrameBG(img,msk, ICQFRAME_BOTTOMMIDLEFT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    x = cx;
    if(img[ICQFRAME_BOTTOMRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMRIGHT], &bmpData);
       x -= bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMRIGHT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    if(img[ICQFRAME_BOTTOMMIDRIGHT] != NO_IMAGE)
    {
       GpiQueryBitmapParameters(img[ICQFRAME_BOTTOMMIDRIGHT], &bmpData);
       x -= bmpData.cx;
       drawFrameBG(img,msk, ICQFRAME_BOTTOMMIDRIGHT, hps, x, 0, bmpData.cx, bmpData.cy);
    }

    /* Release image */
    GpiSetBitmap(hps, NULLHANDLE);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);

    return bg;
#endif
 }
nsresult nsIconChannel::MakeInputStream(nsIInputStream **_retval,
                                        bool nonBlocking)
{

  // get some details about this icon
  nsCOMPtr<nsIFile> localFile;
  uint32_t desiredImageSize;
  nsXPIDLCString contentType;
  nsAutoCString filePath;
  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile),
                                       &desiredImageSize, contentType,
                                       filePath);
  NS_ENSURE_SUCCESS(rv, rv);

  // if the file exists, get its path
  bool fileExists = false;
  if (localFile) {
    localFile->GetNativePath(filePath);
    localFile->Exists(&fileExists);
  }

  // get the file's icon from either the WPS or PM
  bool fWpsIcon = false;
  HPOINTER hIcon = GetIcon(filePath, fileExists,
                           desiredImageSize <= 16, &fWpsIcon);
  if (hIcon == NULLHANDLE)
    return NS_ERROR_FAILURE;

  // get the color & mask bitmaps used by the icon
  POINTERINFO IconInfo;
  if (!WinQueryPointerInfo(hIcon, &IconInfo)) {
    DestroyIcon(hIcon, fWpsIcon);
    return NS_ERROR_FAILURE;
  }

  // if we need a mini-icon, use those bitmaps if present;
  // otherwise, signal that the icon needs to be shrunk
  bool fShrink = FALSE;
  if (desiredImageSize <= 16) {
    if (IconInfo.hbmMiniPointer) {
      IconInfo.hbmColor = IconInfo.hbmMiniColor;
      IconInfo.hbmPointer = IconInfo.hbmMiniPointer;
    } else {
      fShrink = TRUE;
    }
  }

  // various resources to be allocated
  PBITMAPINFO2  pBMInfo = 0;
  uint8_t*      pInBuf  = 0;
  uint8_t*      pOutBuf = 0;
  HDC           hdc     = 0;
  HPS           hps     = 0;

  // using this dummy do{...}while(0) "loop" guarantees that resources will
  // be deallocated, but eliminates the need for nesting, and generally makes
  // testing for & dealing with errors pretty painless (just 'break')
  do {
    rv = NS_ERROR_FAILURE;

    // get the details for the color bitmap;  if there isn't one
    // or this is 1-bit color, exit
    BITMAPINFOHEADER2  BMHeader;
    BMHeader.cbFix = sizeof(BMHeader);
    if (!IconInfo.hbmColor ||
        !GpiQueryBitmapInfoHeader(IconInfo.hbmColor, &BMHeader) ||
        BMHeader.cBitCount == 1)
      break;

    // alloc space for the color bitmap's info, including its color table
    uint32_t cbBMInfo = sizeof(BITMAPINFO2) + (sizeof(RGB2) * 255);
    pBMInfo = (PBITMAPINFO2)nsMemory::Alloc(cbBMInfo);
    if (!pBMInfo)
      break;

    // alloc space for the color bitmap data
    uint32_t cbInRow = ALIGNEDBPR(BMHeader.cx, BMHeader.cBitCount);
    uint32_t cbInBuf = cbInRow * BMHeader.cy;
    pInBuf = (uint8_t*)nsMemory::Alloc(cbInBuf);
    if (!pInBuf)
      break;
    memset(pInBuf, 0, cbInBuf);

    // alloc space for the BGRA32 bitmap we're creating
    uint32_t cxOut    = fShrink ? BMHeader.cx / 2 : BMHeader.cx;
    uint32_t cyOut    = fShrink ? BMHeader.cy / 2 : BMHeader.cy;
    uint32_t cbOutBuf = 2 + ALIGNEDBPR(cxOut, 32) * cyOut;
    pOutBuf = (uint8_t*)nsMemory::Alloc(cbOutBuf);
    if (!pOutBuf)
      break;
    memset(pOutBuf, 0, cbOutBuf);

    // create a DC and PS
    DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    hdc = DevOpenDC((HAB)0, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    if (!hdc)
      break;

    SIZEL sizel = {0,0};
    hps = GpiCreatePS((HAB)0, hdc, &sizel, GPIA_ASSOC | PU_PELS | GPIT_MICRO);
    if (!hps)
      break;

    // get the color bits
    memset(pBMInfo, 0, cbBMInfo);
    *((PBITMAPINFOHEADER2)pBMInfo) = BMHeader;
    GpiSetBitmap(hps, IconInfo.hbmColor);
    if (GpiQueryBitmapBits(hps, 0L, (LONG)BMHeader.cy,
                           (BYTE*)pInBuf, pBMInfo) <= 0)
      break;

    // The first 2 bytes are the width & height of the icon in pixels,
    // the remaining bytes are BGRA32 (B in first byte, A in last)
    uint8_t* outPtr = pOutBuf;
    *outPtr++ = (uint8_t)cxOut;
    *outPtr++ = (uint8_t)cyOut;

    // convert the color bitmap
    pBMInfo->cbImage = cbInBuf;
    ConvertColorBitMap(pInBuf, pBMInfo, outPtr, fShrink);

    // now we need to tack on the alpha data, so jump back to the first
    // pixel in the output buffer
    outPtr = pOutBuf+2;

    // Get the mask info
    BMHeader.cbFix = sizeof(BMHeader);
    if (!GpiQueryBitmapInfoHeader(IconInfo.hbmPointer, &BMHeader))
      break;

    // if the existing input buffer isn't large enough, reallocate it
    cbInRow = ALIGNEDBPR(BMHeader.cx, BMHeader.cBitCount);
    if ((cbInRow * BMHeader.cy) > cbInBuf)  // Need more for mask
    {
      cbInBuf = cbInRow * BMHeader.cy;
      nsMemory::Free(pInBuf);
      pInBuf = (uint8_t*)nsMemory::Alloc(cbInBuf);
      memset(pInBuf, 0, cbInBuf);
    }

    // get the mask/alpha bits
    memset(pBMInfo, 0, cbBMInfo);
    *((PBITMAPINFOHEADER2)pBMInfo) = BMHeader;
    GpiSetBitmap(hps, IconInfo.hbmPointer);
    if (GpiQueryBitmapBits(hps, 0L, (LONG)BMHeader.cy,
                           (BYTE*)pInBuf, pBMInfo) <= 0)
      break;

    // convert the mask/alpha bitmap
    pBMInfo->cbImage = cbInBuf;
    ConvertMaskBitMap(pInBuf, pBMInfo, outPtr, fShrink);

    // create a pipe
    nsCOMPtr<nsIInputStream> inStream;
    nsCOMPtr<nsIOutputStream> outStream;
    rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream),
                    cbOutBuf, cbOutBuf, nonBlocking);
    if (NS_FAILED(rv))
      break;

    // put our data into the pipe
    uint32_t written;
    rv = outStream->Write(reinterpret_cast<const char*>(pOutBuf),
                          cbOutBuf, &written);
    if (NS_FAILED(rv))
      break;

    // success! so addref the pipe
    NS_ADDREF(*_retval = inStream);
  } while (0);

  // free all the resources we allocated
  if (pOutBuf)
    nsMemory::Free(pOutBuf);
  if (pInBuf)
    nsMemory::Free(pInBuf);
  if (pBMInfo)
    nsMemory::Free(pBMInfo);
  if (hps) {
    GpiAssociate(hps, NULLHANDLE);
    GpiDestroyPS(hps);
  }
  if (hdc)
    DevCloseDC(hdc);
  if (hIcon)
    DestroyIcon(hIcon, fWpsIcon);

  return rv;
}
Пример #24
0
BOOL CreateImages(PLUGINSHARE *pPluginData)
{
    int     i;
    HBITMAP hbmTemp;
    HAB     hab = WinQueryAnchorBlock(HWND_DESKTOP);
    HDC     hdcSrc, hdcDest;
    HPS     hpsSrc, hpsDest;
    SIZEL   slHPS;
    BITMAPINFOHEADER2 bif2Src, bif2Dest;
    POINTL aptl[4];

    if (pPluginData == NULL)
        return (FALSE);

    hbmTemp = SetupBitmapFromFile(HWND_DESKTOP, pPluginData->szImageFile/*, 22*/);

    if (hbmTemp == NULLHANDLE)
        return FALSE;

    memset(&bif2Src, 0, sizeof(bif2Src));
    bif2Src.cbFix = sizeof(bif2Src);
    GpiQueryBitmapInfoHeader(hbmTemp, &bif2Src);
    hdcSrc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);
    slHPS.cx = bif2Src.cx;
    slHPS.cy = bif2Src.cy;
    pPluginData->ulCx=slHPS.cx;
    pPluginData->ulCy=slHPS.cy;

    hpsSrc = GpiCreatePS(hab,
                      hdcSrc,
                      &slHPS,
                      PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
    GpiSetBitmap(hpsSrc, hbmTemp);

    hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);


    slHPS.cx = bif2Src.cx / 2;
    slHPS.cy = bif2Src.cy / 5;
    hpsDest = GpiCreatePS(hab,
                      hdcDest,
                      &slHPS,
                      PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

    memset(&bif2Dest, 0, sizeof(bif2Dest));
    bif2Dest.cbFix = sizeof(bif2Dest);
    bif2Dest.cx = slHPS.cx;
    bif2Dest.cy = slHPS.cy;
    bif2Dest.cBitCount = 24;
    bif2Dest.cPlanes = 1;

//Close Button
    pPluginData->hbmActiveClose = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveClose);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = 0;
    aptl[3].x = slHPS.cx;
    aptl[3].y = slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Minimize Button
    pPluginData->hbmActiveMinimize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveMinimize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 1;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Maximize Button
    pPluginData->hbmActiveMaximize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveMaximize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 2;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Restore Button
    pPluginData->hbmActiveRestore = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveRestore);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 3;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Hide Button
    pPluginData->hbmActiveHide = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmActiveHide);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = 0;
    aptl[2].y = slHPS.cy * 4;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);



    /* Inactive... */

//Close Button
    pPluginData->hbmInactiveClose = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveClose);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx ;
    aptl[2].y = 0;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Minimize Button
    pPluginData->hbmInactiveMinimize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMinimize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 1;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

//Maximize Button
    pPluginData->hbmInactiveMaximize = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMaximize);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 2;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);


//Restore Button
    pPluginData->hbmInactiveRestore = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveRestore);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 3;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);


//Hide Button
    pPluginData->hbmInactiveHide = GpiCreateBitmap(hpsDest,
                                    &bif2Dest,
                                    0L,
                                    NULL,
                                    NULL);

    GpiSetBitmap(hpsDest, pPluginData->hbmInactiveHide);

    aptl[0].x = 0;
    aptl[0].y = 0;
    aptl[1].x = slHPS.cx;
    aptl[1].y = slHPS.cy;
    aptl[2].x = slHPS.cx;
    aptl[2].y = slHPS.cy * 4;
    aptl[3].x = aptl[2].x + slHPS.cx;
    aptl[3].y = aptl[2].y + slHPS.cy;
    GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE);

   GpiSetBitmap(hpsSrc, NULLHANDLE);

    if (hbmTemp != NULLHANDLE)
        GpiDeleteBitmap(hbmTemp);
    if (hpsSrc != NULLHANDLE)
        GpiDestroyPS(hpsSrc);
    if (hdcSrc != NULLHANDLE)
        DevCloseDC(hdcSrc);


    GpiSetBitmap(hpsDest, NULLHANDLE);
    if (hpsDest != NULLHANDLE)
        GpiDestroyPS(hpsDest);
    if (hdcDest != NULLHANDLE)
        DevCloseDC(hdcDest);

    return TRUE;
}
Пример #25
0
HBITMAP SetupBitmapFromFile(HWND hwnd, char *pszFileName /*, long lVertical2*/)
{
    HAB hab = WinQueryAnchorBlock(hwnd);
    PSTBFILE *pFile;
    HBITMAP hbm;

    if (DosAllocMem((PPVOID) & pFile, sizeof(PSTBFILE), PAG_READ | PAG_WRITE | PAG_COMMIT)
            != NO_ERROR)
    {
        return (NULLHANDLE);
    }
    memset(pFile, 0, sizeof(PSTBFILE));

    if (PSMMFillImageFormat(pszFileName, &(pFile->mmFormat), &(pFile->mmioInfo)) != TRUE)
    {
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    if ((pFile->hmmio = PSMMInitializeImageFile(pszFileName,
                                                &(pFile->mmioInfo),
                                         &(pFile->mmImgHdr))) == NULLHANDLE)
    {
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    pFile->cbRow = ((pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx *
      pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount + 31) / 32) * 4;
    pFile->cbData = pFile->cbRow * pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;

    if (DosAllocMem(&(pFile->pvImage), pFile->cbData, PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR)
    {
        PSMMCloseImageFile(pFile->hmmio);
        DosFreeMem(pFile);
        return (NULLHANDLE);
    }
    if (PSMMReadImageFile(pFile->hmmio, pFile->pvImage, pFile->cbData) != TRUE)
    {
        DosFreeMem(pFile->pvImage);
        PSMMCloseImageFile(pFile->hmmio);
        DosFreeMem(pFile);
    }
    PSMMCloseImageFile(pFile->hmmio);

    // convert data to system bitcount
    pFile->hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE);
    pFile->slHPS.cx = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
    pFile->slHPS.cy = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
    pFile->hps = GpiCreatePS(hab,
                             pFile->hdc,
                             &(pFile->slHPS),
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
    pFile->hbm = GpiCreateBitmap(pFile->hps,
                             &(pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2),
                                 0L,
                                 NULL,
                                 NULL);
    GpiSetBitmap(pFile->hps, pFile->hbm);
    GpiSetBitmapBits(pFile->hps,
                     0L,
                     (long) pFile->slHPS.cy,
                     (PBYTE) pFile->pvImage,
            (PBITMAPINFO2) & (pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2));

    hbm = pFile->hbm;

    GpiDeleteBitmap(pFile->hbm);

    // free everything up
    GpiSetBitmap(pFile->hps, NULLHANDLE);
    GpiDestroyPS(pFile->hps);
    DevCloseDC(pFile->hdc);
    DosFreeMem(pFile->pvImage);
    DosFreeMem(pFile);

    return (hbm);
}
/*************************************************************************
 *
 * Name       : WinProc(hwnd, msg, mp1, mp2)
 *
 * Description: Processes the messages sent to the main client
 *              window.  This routine processes the basic
 *              messages all client windows should process.
 *
 * Concepts   : This procedure provides service routines for the general
 *              PM events (messages) that PM sends to the window, as well
 *              as the user initiated events (messages) that are generated
 *              when the user selects the action bar and pulldown menu
 *              controls or the corresponding keyboard accelerators.
 *
 *              The switch statement shown below distributes the window
 *              messages to the respective message service routines, which
 *              are set apart by the case statements.  The window
 *              procedures must provide an appropriate service routine for
 *              its end user initiated messages, as well as the general PM
 *              messages (like the WM_CLOSE message). If a message is sent
 *              to this procedure for which there is no programmed case
 *              clause (i.e., no service routine), the message is defaulted
 *              function WinDefWindowProc, where it is disposed of by PM.
 *
 *              Time-consuming tasks are posted to the object window where
 *              they can be performed without the 1/10 second turnaround
 *              time imposed on the client window. When the object window
 *              is busy, the client window is usually disabled. The object
 *              window then posts an acknowledgement
 *              back to the client when the lengthy task is completed.
 *
 *              Cases under the big switch appear in alphabetical order.
 *
 *  API's     :   WinLoadString
 *                WinMessageBox
 *                WinQueryWindowULong
 *                WinSendMsg
 *                WinPostMsg
 *                WinIsWindowEnabled
 *                WinSetPointer
 *                WinQuerySysPointer
 *                WinBeginPaint
 *                WinQueryWindowRect
 *                WinFillRect
 *                WinEndPaint
 *                WinInvalidateRect
 *                WinSetWindowText
 *                GpiDrawChain
 *                GpiConvert
 *                GpiSetDefaultViewMatrix
 *                GpiAssociate
 *                GpiDestroyPS
 *                GpiDeleteBitmap
 *                GpiDeleteMetafile
 *
 * Parameters : HWND         window handle
 *              ULONG        message
 *              MPARAM       message parameter 1
 *              MPARAM       message parameter 2
 *
 * Result     : MRESULT      message result
 *
 *************************************************************************/
MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
   BOOL                bOK;
   PMAIN_PARM       pmp;
   HPS                 hps;
   RECTL              rectl;
   PSZ                 psz;
   CHAR               szWork[ LEN_WORKSTRING ];
   SHORT              sStep;
   ULONG              ulWork;
   SHORT              sNewPos;
   ULONG              rc;

   switch(msg)
   {
   case WM_CLOSE:
      /* obtain the main parameter pointer from window words */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
#ifdef OSA_AWARE
      /* Do OSA termination */
      TerminateOSA(hwnd);
#endif
      if( pmp->fBusy )
      {
         /* OK to close when object window is busy?  */
         WinLoadString( pmp->hab, (HMODULE)NULLHANDLE,
                   ERRMSG_CLOSE_QUESTION, LEN_WORKSTRING, szWork );
         ulWork = WinMessageBox( HWND_DESKTOP,
                                 pmp->hwndFrame,
                                 szWork,
                                 pmp->pszTitle,
                                 (USHORT)0,
                                 MB_YESNOCANCEL | MB_MOVEABLE |
                                 MB_CUANOTIFICATION | MB_APPLMODAL);

         if( ulWork == MBID_YES )
         {
            /* close down the application in spite of being busy */
            pmp->fCancel = TRUE;
            /* disable client during exit */
            WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0 , (MPARAM)0  );
            /* start a watchdog timer to ensure a timely death */
            WinStartTimer( pmp->hab, hwnd, ID_DEATH_TIMER, LEN_DEATH_TIMER );
            /* Tell object window to close, quit, and post me a WM_QUIT */
            WinPostMsg( pmp->hwndObject, WM_USER_CLOSE, (MPARAM)hwnd, (MPARAM)0 );
         }
      }
      else
      {
         /* not busy, so initiate closure by telling object window to close */
         WinPostMsg( pmp->hwndObject, WM_USER_CLOSE, (MPARAM)hwnd, (MPARAM)0 );
      }
      return (MRESULT)NULL;


   case WM_COMMAND:
      /* do menu activities; see menu.c */
      return Menu( hwnd, msg, mp1, mp2 );


   case WM_CREATE:

      /*
       * Do one-time, startup processing in PRTCREAT.C.
       * This function allocates the pmp, a pointer to the program's
       * main parameters. See the declaration of this block of
       * parameters in PRTSAMP.H, the MAIN_PARM structure.
       *
       * The Create() function allocates this structure and
       * begins to initialize it. Throughout all the code, the pmp->
       * pointer is usually obtainable with a call to WinQueryWindowULong.
       * Window word space for this pointer was reserved on the call
       * to WinRegisterClass.
       *
       * Create() allocates, initializes, and stores the pmp pointer
       * in the client window words. It then starts thread 2 of the
       * application on which the object window operates. The pmp
       * pointer is passed to thread 2 with _beginthread in PRTCREAT.C.
       * The pmp is passed to the object window on the call to
       * WinCreateWindow in PRTOBJ.C. Finally, the object window stores
       * the pmp in its window words under the WM_CREATE case of the
       * ObjectWinProc in PRTOBJ.C.
       *
       */

      Create( hwnd );
#ifdef OSA_AWARE
      /* Do OSA Initialization */
      InitOSA(hwnd);
#endif

#ifdef OSA_AWARE
        /* Generate a Apple Event - Open Application to myself  (Workaround) */
        rc =  GenerateOSAEvent(hwnd, msg, MPFROMSHORT(IDM_AEOPENAPP), mp2);
#endif
      return (MRESULT)NULL;


   case WM_HSCROLL:
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /* Compute some fraction of scroll bar range for a unit of scrolling. */
      sStep  = pmp->sHScrollRange / 50;

      switch( SHORT2FROMMP( mp2 ))
      {
      case SB_LINELEFT:
         pmp->sHScrollPos -= sStep;
         break;
      case SB_PAGELEFT:
         pmp->sHScrollPos -= pmp->sizelClient.cx;
         break;
      case SB_LINERIGHT:
         pmp->sHScrollPos += sStep;
         break;
      case SB_PAGERIGHT:
         pmp->sHScrollPos += pmp->sizelClient.cx;
         break;
      case SB_SLIDERPOSITION:
      case SB_SLIDERTRACK:
         pmp->sHScrollPos = SHORT1FROMMP( mp2 );
         break;
      }

      /* Don't allow step assignments to exceed limits of zero to range. */
      pmp->sHScrollPos = max( (SHORT)0,
                              min( pmp->sHScrollPos, pmp->sHScrollRange ));

      if( pmp->sHScrollPos != SHORT1FROMMR(WinSendMsg( pmp->hwndHScroll,
          SBM_QUERYPOS, (MPARAM)0, (MPARAM)0 )))
      {
         /*
          * New scroll bar thumbbutton position is different than current.
          * Set a new X translation value to effect the scroll.
          * Current scale setting affects the X element of the matrix.
          */
         pmp->matlfDefView.lM31 = OFFSET_XY_TWIPS - (LONG)(pmp->floatScale *
                                                 (float)( pmp->sHScrollPos));
         bOK = GpiSetDefaultViewMatrix( pmp->hpsClient,
                                        9,
                                        &pmp->matlfDefView,
                                        TRANSFORM_REPLACE );
         pmassert( pmp->hab, bOK );
         CalibrateHorizontalScrollBar( pmp );
         WinInvalidateRect( hwnd, NULL, FALSE );
      }
      return (MRESULT) 0;


   case WM_MOUSEMOVE:
      /* display which pointer? -- could query pmp->fBusy or... */
      if( WinIsWindowEnabled( hwnd ))
      {
         /* not disabled; display regular pointer */
         WinSetPointer( HWND_DESKTOP,
                        WinQuerySysPointer( HWND_DESKTOP, SPTR_ARROW, FALSE ));
      }
      else
      {
         /* disabled; display hourglass because I'm busy */
         WinSetPointer( HWND_DESKTOP,
                        WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE ));
      }
     return (MRESULT) 1;



   case WM_NACK_BITMAP_NOT_SUPPORTED:
      /*
       * Object window does not support this format of bitmap -
       * show a message box.
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
      bOK = WinLoadString( pmp->hab, (HMODULE)0,
                   ERRMSG_BITMAP_NOT_SUPPORTED, LEN_WORKSTRING, szWork );
      pmassert( pmp->hab, bOK );
      WinMessageBox( HWND_DESKTOP,
                     pmp->hwndFrame,
                     szWork,
                     pmp->pszTitle,
                     (USHORT)0,
                     MB_OK | MB_MOVEABLE | MB_CUACRITICAL | MB_APPLMODAL);

      pmp->ulNextMode        = MODE_UNKNOWN;
      pmp->szNextFilename[0] = 0;
      WinPostMsg( hwnd, WM_USER_NEW_MODE, (MPARAM)0, (MPARAM)0 );
      return (MRESULT) 0;


   case WM_NACK_BITMAP_ERROR:
      /*
       * Object window had error loading the bitmap file -
       * show a message box
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
      bOK = WinLoadString( pmp->hab,
                           (HMODULE)NULLHANDLE,
                           ERRMSG_BAD_BITMAP,
                           LEN_WORKSTRING,
                           szWork );
      pmassert( pmp->hab, bOK );
      WinMessageBox( HWND_DESKTOP,
                     pmp->hwndFrame,
                     szWork,
                     pmp->pszTitle,
                     (USHORT)0,
                     MB_OK | MB_MOVEABLE | MB_CUAWARNING | MB_APPLMODAL);

      pmp->ulNextMode        = MODE_UNKNOWN;
      pmp->szNextFilename[0] = 0;
      WinPostMsg( hwnd, WM_USER_NEW_MODE, (MPARAM)0, (MPARAM)0 );
      return (MRESULT) 0;


   case WM_NACK_FILE_READING_ERROR:
      /*
       * Object window had a problem with reading the disk -
       * show a message box.
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
      bOK = WinLoadString( pmp->hab, (HMODULE)NULLHANDLE,
                           ERRMSG_READ_ERROR, LEN_WORKSTRING, szWork );
      pmassert( pmp->hab, bOK );
      WinMessageBox( HWND_DESKTOP,
                     pmp->hwndFrame,
                     szWork,
                     pmp->pszTitle,
                     (USHORT)0,
                     MB_OK | MB_MOVEABLE | MB_CUACRITICAL | MB_APPLMODAL);
      pmp->ulNextMode        = MODE_UNKNOWN;
      pmp->szNextFilename[0] = 0;
      WinPostMsg( hwnd, WM_USER_NEW_MODE, (MPARAM)0, (MPARAM)0 );
      return (MRESULT) 0;


   case WM_PAINT:
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /* do not rely on client window rectangle being correct */
      WinQueryUpdateRect( hwnd, &rectl );
      WinQueryWindowRect( hwnd, &rectl );

      /* current mode of the program affects window painting */
      switch( pmp->ulMode )
      {
      case MODE_UNKNOWN:
         WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
         WinPostMsg( pmp->hwndObject, WM_USER_PAINT_DEFAULT_SCREEN,
                        (MPARAM)hwnd, (MPARAM)0 );
         /* must call default window proc for window validation */
         break;

      case MODE_TEXT:
         if( pmp->fBusy )
         {
            /*
             * Object window is busy with the client PS drawing into
             * retained segments. Use a cached micro PS to merely
             * fill the client window with a background wash.
             *
             * Proper painting of the text will occur in due time
             * because the WM_USER_ACK case below will
             * invalidate the client window and force a paint.
             * The object window won't be busy then.
             */
            hps = WinBeginPaint( hwnd, (HPS) 0, &rectl );
            pmassert( pmp->hab, hps );
            bOK = WinFillRect( hps, &rectl, SYSCLR_WINDOW );
            pmassert( pmp->hab, bOK );
            WinEndPaint( hps );
         }
         else
         {
            /* PS not busy. Use GpiDrawChain to repaint the text */
            hps = WinBeginPaint( hwnd, (HPS)pmp->hpsClient, &rectl );
            pmassert( pmp->hab, hps );
            bOK = WinFillRect( pmp->hpsClient, &rectl, SYSCLR_WINDOW );
            pmassert( pmp->hab, bOK );
            /*
             * GpiDrawChain re-plays the GpiCharString orders that were
             * retain in the WM_USER_PAGINATE case in prtobj.c
             */
            bOK = GpiDrawChain( pmp->hpsClient );
            pmassert( pmp->hab, bOK );
            bOK = WinEndPaint( pmp->hpsClient );
            pmassert( pmp->hab, bOK );
         }
         return (MRESULT) 0;

      case MODE_BITMAP:
         if( pmp->hbm )
         {
            WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
            WinPostMsg( pmp->hwndObject, WM_USER_PAINT_BITMAP,
                        (MPARAM)hwnd, (MPARAM)0 );
         }
         /* must call default window proc for window validation */
         break;

      case MODE_METAFILE:
         hps = WinBeginPaint( hwnd, (HPS) 0, &rectl );
         pmassert( pmp->hab, hps );
         WinFillRect( hps, &rectl, SYSCLR_WINDOW );
         if( pmp->hmf )
         {
            WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
            WinPostMsg( pmp->hwndObject, WM_USER_PAINT_METAFILE,
                        (MPARAM)hwnd, (MPARAM)0 );
         }
         WinEndPaint( hps );
         return (MRESULT) 0;

      default:
         pmassert( pmp->hab, NULL == "bad case in WM_PAINT" );
      }
      break;


#ifdef OSA_AWARE
   case WM_SEMANTICEVENT:
      /* Handle Apple Event Manager Semantic Event */
      WinMessageBox( HWND_DESKTOP,
                     HWND_DESKTOP,
                     "WM_SEMANTIC_EVENT was received",
                     "WinProc",
                     (USHORT)0,
                     MB_OK | MB_NOICON);
      /* Call ProcessSemanticEvent to process the Apple Event */
      ProcessSemanticEvent( hwnd, msg, mp1, mp2 );
      return (MRESULT) 0;
#endif


   case WM_SIZE:
      /* Do size process if frame is not minimized  */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /*
       * If the object window is busy drawing, the GPI calls here can fail
       * because the PS is busy. Check for this situation and delay
       * the sizing operation by a few milliseconds.
       */
      if( pmp->fBusy )
      {
          WinStartTimer( pmp->hab, hwnd, ID_SIZE_TIMER, LEN_SIZE_TIMER );
          return (MRESULT) 0;
      }

      ulWork = WinQueryWindowULong( pmp->hwndFrame, QWL_STYLE );

      if( !( ulWork & WS_MINIMIZED ))
      {
         /* Frame is not minimized. Get window size in pels. */
         WinQueryWindowRect( hwnd, &rectl );

         /* how many twips will fit into the client window now? */
         bOK = GpiConvert( pmp->hpsClient, CVTC_DEVICE,
                           CVTC_WORLD, 2L, (PPOINTL)&rectl );
         pmassert( pmp->hab, bOK );

         /* compute client size in twips, store in pmp */
         pmp->sizelClient.cx = rectl.xRight - rectl.xLeft;
         pmp->sizelClient.cy = rectl.yTop   - rectl.yBottom;

         /* Try to keep the current position still in view by calculating */
         /* the difference between size required and client window. */
         /* The scroll position is then either 0 or the minimum of the */
         /* difference and the old scroll position */
         sNewPos = (LONG)FixedInchesToTwips(pmp->form.fxxWidth) +
                    (((float)(2 * OFFSET_XY_TWIPS)) / pmp->floatScale) -
                   pmp->sizelClient.cx;
         pmp->sHScrollPos = min( max( 0, sNewPos), pmp->sHScrollPos);
         sNewPos = (LONG)FixedInchesToTwips(pmp->form.fxyHeight) +
                    (((float)(2 * OFFSET_XY_TWIPS)) / pmp->floatScale) -
                   pmp->sizelClient.cy;
         pmp->sVScrollPos = min( max( 0, sNewPos), pmp->sVScrollPos);

         /* recalibrate the scroll bars */
         CalibrateHorizontalScrollBar( pmp );
         CalibrateVerticalScrollBar( pmp );

         /*
          * Modify def-view matrix translation to home the displayed page.
          * This depends on the current scaling value.
          */
         pmp->matlfDefView.lM31 = OFFSET_XY_TWIPS - (LONG)(pmp->floatScale *
                                                 (float)( pmp->sHScrollPos));
         pmp->matlfDefView.lM32 = OFFSET_XY_TWIPS + (LONG)(pmp->floatScale *
                          (float)( pmp->sVScrollPos - pmp->sVScrollRange ));
         bOK = GpiSetDefaultViewMatrix( pmp->hpsClient, 9,
                          &pmp->matlfDefView, TRANSFORM_REPLACE );
         pmassert( pmp->hab, bOK );

         /* force a paint */
         WinInvalidateRect( hwnd, NULL, FALSE );
      }
      return (MRESULT) 0;




   case WM_TIMER:
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      switch( (ULONG) mp1 )
      {
      case ID_DEATH_TIMER:
         /* object window never posted a quit in allotted time.
         WinPostMsg( hwnd, WM_QUIT, 0, 0 );
         break;
      case ID_SIZE_TIMER:
         /* object window was busy with the PS before; try sizing now */
         bOK = WinStopTimer( pmp->hab, hwnd, ID_SIZE_TIMER );
         pmassert( pmp->hab, bOK );
         WinSendMsg( hwnd, WM_SIZE, 0, 0 );
         break;
      }
      return (MRESULT) 0;





   case WM_USER_ACK:
      /*
       * Object window is done processing lengthy task.
       * mp1 contains the WM_USER msg originally posted to the object window
       * mp2 may contain a result code, depending on mp1
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /* reenable the client window */
      WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, (MPARAM)0, (MPARAM)0 );

      switch( (ULONG)mp1 )
      {
      case WM_USER_LOAD_BITMAP:
      case WM_USER_LOAD_METAFILE:
      case WM_USER_LOAD_TEXT:
         /*
          * Do size processing so that document will
          * "home" in the client window.
          */
         WinSendMsg( hwnd, WM_SIZE, (MPARAM)0, (MPARAM)0 );
         break;
      case WM_USER_PAGINATE:
         switch( (ULONG)mp2  )
         {
         case PAGINATE_EOF:
         case PAGINATE_EOF_PART_PAGE:
            /* seek top of file */
            fseek( pmp->f, 0, SEEK_SET );
         }
         WinInvalidateRect( hwnd, NULL, FALSE );
         break;
      }

      return (MRESULT) 0;


   case WM_USER_DISABLE_CLIENT:
      /*
       * usually disable before posting a task to the object window
       * this message may be sent; disable menu action bar as well
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      pmp->fBusy = TRUE;
      WinEnableWindow( pmp->hwndClient,  FALSE );
      WinEnableWindow( pmp->hwndMenubar, FALSE );
      WinEnableControl( pmp->hwndFrame, FID_HORZSCROLL,  FALSE );
      WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL,  FALSE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, FALSE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, FALSE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, FALSE );
      return (MRESULT)0;


   case WM_USER_ENABLE_CLIENT:
      /*
       * usually enable upon receipt of object window ack/nack
       * this message may be sent; enable menu actions if text mode
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
      pmp->fBusy = FALSE;
      WinEnableWindow( pmp->hwndClient,  TRUE );
      WinEnableWindow( pmp->hwndMenubar, TRUE );
      WinEnableControl( pmp->hwndFrame, FID_HORZSCROLL,  TRUE );
      WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL,  TRUE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, TRUE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, TRUE );
      if( pmp->ulMode == MODE_TEXT )
      {
         WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, TRUE );
      }
      return (MRESULT) 0;



   case WM_USER_NEW_MODE:
      /*
       * The program now has a new file, file type, or printer, or
       * printer form, orientation, resolution, etc. The receipt
       * and processing of this message works to reset the program:
       * Old file, bitmap, or metafile handles are closed, and
       * new ones get opened. The titlebar shows the new filename.
       * This case works very much like a program reset.
       */
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /* close processing on current file */

      switch( pmp->ulMode )
      {
      case MODE_BITMAP:
        /* destroy previous memory dc, ps, and hbm */
        if( pmp->hpsMemory )
        {
          GpiAssociate( pmp->hpsMemory, (HDC)0 );
          GpiDestroyPS( pmp->hpsMemory );
          pmp->hpsMemory = (HPS) 0;
        }
        if( pmp->hdcMemory )
        {
          DevCloseDC( pmp->hdcMemory );
          pmp->hdcMemory = (HDC) 0;
        }
        if( pmp->hbm )
        {
          GpiDeleteBitmap( pmp->hbm );
          pmp->hbm = (HBITMAP) 0;
        }
        break;

      case MODE_METAFILE:
        /* destroy old metafile handle */
        if( pmp->hmf )
        {
          GpiDeleteMetaFile( pmp->hmf );
          pmp->hmf = (HMF) 0;
        }
        break;

      case MODE_TEXT:
        fclose( pmp->f );
        pmp->f = (FILE *) 0;
        /* turn off options for text mode */
        WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, FALSE );
        WinEnableMenuItem( pmp->hwndMenubar, IDM_SETFONT,  FALSE );
        break;
      }

      /* turn off options for all modes */
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, FALSE );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, FALSE );
      WinEnableControl( pmp->hwndFrame, FID_HORZSCROLL,  FALSE );
      WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL,  FALSE );

      /* copy over current values with the next values */
      pmp->ulMode = pmp->ulNextMode;
      strcpy( pmp->szFilename, pmp->szNextFilename );

      /* enable the print menu option if mode is known and there
         is a printer set up. */
      WinEnableMenuItem( pmp->hwndMenubar, IDM_PRINT,
       (pmp->ulMode != MODE_UNKNOWN && pmp->hpsPrinterInfo ) );


      /* update title bar text and show filename in use */
      if( *pmp->szFilename )
      {
         /* parse full-qualified filename to just get filename and extension */
         psz = strrchr( pmp->szFilename, '\\' );
         if (psz && *psz)
         {
             ++psz;
         }
         else
         {
             psz = pmp->szFilename;
         }
         sprintf( szWork, "%s - %s", pmp->pszTitle, psz );
      }
      else
      {
         strcpy( szWork, pmp->pszTitle );
      }
      WinSetWindowText( pmp->hwndTitlebar, szWork );

      /* enable options for all modes */
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, TRUE  );
      WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, TRUE  );
      WinEnableControl( pmp->hwndFrame, FID_HORZSCROLL,  TRUE  );
      WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL,  TRUE  );

      /* process this new mode */
      switch( pmp->ulMode )
      {
      case MODE_BITMAP:
        /* load the bitmap into memory so it is compatible with the screen */
        WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
        WinPostMsg( pmp->hwndObject, WM_USER_LOAD_BITMAP,
                    (MPARAM)hwnd, (MPARAM)FLAGS_SCREEN );
        break;

      case MODE_METAFILE:
        /* make object window read metafile */
        WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
        WinPostMsg( pmp->hwndObject, WM_USER_LOAD_METAFILE, (MPARAM)hwnd, 0 );
        break;

      case MODE_TEXT:
        /* turn on options for text mode */
        WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, TRUE  );
        WinEnableMenuItem( pmp->hwndMenubar, IDM_SETFONT,  TRUE  );
        /* reset view matrix that was last in effect for viewing text pages; */
        /* this gets lost after viewing a metafile */
        bOK = GpiSetDefaultViewMatrix( pmp->hpsClient, 9,
                                       &pmp->matlfDefView, TRANSFORM_REPLACE );
        pmassert( pmp->hab, bOK );
        /* disable until text loaded */
        WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
        /* tell object window to load the text file */
        bOK = WinPostMsg( pmp->hwndObject, WM_USER_LOAD_TEXT, (MPARAM)hwnd, 0 );
        pmassert( pmp->hab, bOK );
        break;


      case MODE_UNKNOWN:
        /* size screen to get correct scrollbars */
        WinPostMsg( pmp->hwndClient, WM_SIZE, 0, 0 );
        break;

      }
      return (MRESULT) 0;

   case WM_VSCROLL:
      pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );

      /* Compute some fraction of scroll bar range for a unit of scrolling. */
      sStep  = pmp->sVScrollRange / 50;

      switch( SHORT2FROMMP( mp2 ))
      {
      case SB_LINEUP:
         pmp->sVScrollPos -= sStep;
         break;
      case SB_PAGEUP:
         pmp->sVScrollPos -= pmp->sizelClient.cy;
         break;
      case SB_LINEDOWN:
         pmp->sVScrollPos += sStep;
         break;
      case SB_PAGEDOWN:
         pmp->sVScrollPos += pmp->sizelClient.cy;
         break;
      case SB_SLIDERPOSITION:
      case SB_SLIDERTRACK:
         sNewPos          = SHORT1FROMMP( mp2 );
         pmp->sVScrollPos = sNewPos;
         break;
      }

      /* Don't allow step assignments to exceed limits of zero to range. */
      pmp->sVScrollPos = max( (SHORT)0,
                              min( pmp->sVScrollPos, pmp->sVScrollRange ));

      if( pmp->sVScrollPos != SHORT1FROMMR(WinSendMsg( pmp->hwndVScroll,
          SBM_QUERYPOS, (MPARAM)0, (MPARAM)0 )))
      {
         /*
          * New scroll bar thumbbutton position is different than current.
          * Set a new Y translation value to effect the scroll.
          * Current scale setting affects the Y element of the matrix.
          */
         pmp->matlfDefView.lM32 = OFFSET_XY_TWIPS + (LONG)(pmp->floatScale *
                          (float)( pmp->sVScrollPos - pmp->sVScrollRange ));

         pmp->matlfDefView.lM32 =  (LONG)(pmp->floatScale *
             (float)( OFFSET_XY_TWIPS +
                      pmp->sVScrollPos -
                      pmp->sVScrollRange ));

         bOK = GpiSetDefaultViewMatrix( pmp->hpsClient,
                                        9,
                                        &pmp->matlfDefView,
                                        TRANSFORM_REPLACE );
         pmassert( pmp->hab, bOK );
         CalibrateVerticalScrollBar( pmp );
         WinInvalidateRect( hwnd, NULL, FALSE );
      }
      return (MRESULT) 0;
   }
   return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}  /* End of WinProc */
Пример #27
0
HBITMAP PSBMBLTToSize( HAB hab, HPS hps, HBITMAP hbm, float fScale, ULONG ulOptions )
{
    BITMAPINFOHEADER2   bif2Before;
    BITMAPINFOHEADER2   bif2After;
    SIZEL               slAfter;
    ULONG               ulScreenWidth;
    ULONG               ulScreenHeight;
    HDC                 hdcAfter;
    HPS                 hpsAfter;
    HBITMAP             hbmAfter;
    POINTL              aptl[ 4 ];
    float               fAspect;
    HBITMAP             hbmOld;

    if( ( hbmOld = GpiSetBitmap( hps, hbm ) ) == HBM_ERROR )
    {
        return( NULLHANDLE );
    }

    memset( &bif2Before, 0, sizeof( bif2Before ) );                 // get current info
    bif2Before.cbFix = sizeof( bif2Before );
    if( GpiQueryBitmapInfoHeader( hbm, &bif2Before ) != TRUE )
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    ulScreenWidth = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );  // screen width
    ulScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); // screen height

    fAspect = ( bif2Before.cx * 1.0 ) / ( bif2Before.cy * 1.0 );    // calculate aspect ratio

    if( ulOptions & SCALE_LARGEST )
    {
        if( bif2Before.cx > bif2Before.cy )
        {
            slAfter.cx = ( LONG )( ulScreenWidth * fScale );
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
        else
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
            slAfter.cx = ( LONG )( slAfter.cy * fAspect );
        }
    }
    else if( ulOptions & SCALE_SMALLEST )
    {
        if( bif2Before.cx < bif2Before.cy )
        {
            slAfter.cx = ( LONG )( ulScreenWidth * fScale );
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
        else
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
            slAfter.cx = ( LONG )( slAfter.cy * fAspect );
        }
    }
    else if( ulOptions & SCALE_HORIZONTAL )
    {
        slAfter.cx = ( LONG )( ulScreenWidth * fScale );
        if( ulOptions & SCALE_VERTICAL )                        // basically, screw the aspect
        {
            slAfter.cy = ( LONG )( ulScreenHeight * fScale );
        }
        else
        {
            slAfter.cy = ( LONG )( slAfter.cx / fAspect );
        }
    }
    else if( ulOptions & SCALE_VERTICAL )
    {
        slAfter.cy = ( LONG )( ulScreenHeight * fScale );
        slAfter.cx = ( LONG )( slAfter.cy * fAspect );
    }
    else
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    if( ( hdcAfter = DevOpenDC( hab, OD_MEMORY, "*", 0L, ( PDEVOPENDATA )NULL, NULLHANDLE ) )
        == NULLHANDLE )
    {
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }
    if( ( hpsAfter = GpiCreatePS(   hab,
                                    hdcAfter,
                                    &slAfter,
                                    PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC ) ) == NULLHANDLE )
    {
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    memset( &bif2After, 0, sizeof( bif2After ) );
    bif2After.cbFix = sizeof( bif2After );
    bif2After.cx = slAfter.cx;
    bif2After.cy = slAfter.cy;
    bif2After.cBitCount = bif2Before.cBitCount;
    bif2After.cPlanes = bif2Before.cPlanes;

    if( ( hbmAfter = GpiCreateBitmap(   hpsAfter,                 // create bitmap
                                        ( PBITMAPINFOHEADER2 )&( bif2After ),
                                        ( ULONG )FALSE,
                                        NULL,
                                        NULL ) ) == NULLHANDLE )
    {
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    if( GpiSetBitmap( hpsAfter, hbmAfter ) == HBM_ERROR )
    {
        GpiDeleteBitmap( hbmAfter );
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    aptl[ 0 ].x = 0;
    aptl[ 0 ].y = 0;
    aptl[ 1 ].x = slAfter.cx;
    aptl[ 1 ].y = slAfter.cy;
    aptl[ 2 ].x = 0;
    aptl[ 2 ].y = 0;
    aptl[ 3 ].x = bif2Before.cx;
    aptl[ 3 ].y = bif2Before.cy;

    if( GpiBitBlt(  hpsAfter,
                    hps,
                    4L,
                    aptl,
                    ROP_SRCCOPY,
                    BBO_IGNORE ) == GPI_ERROR )
    {
        GpiSetBitmap( hpsAfter, NULLHANDLE );
        GpiDeleteBitmap( hbmAfter );
        GpiDestroyPS( hpsAfter );
        DevCloseDC( hdcAfter );
        GpiSetBitmap( hps, hbmOld );
        return( NULLHANDLE );
    }

    GpiSetBitmapDimension( hbmAfter, &slAfter );

    GpiSetBitmap( hpsAfter, NULLHANDLE );
    GpiDestroyPS( hpsAfter );
    DevCloseDC( hdcAfter );
    GpiSetBitmap( hps, hbmOld );

    return( hbmAfter );
}
Пример #28
0
 HBITMAP icqskin_createBackground(HWND hwnd, HBITMAP base)
 {
    SIZEL                sizl    = { 0, 0 };
    DEVOPENSTRUC         dop     = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
    HAB                  hab     = WinQueryAnchorBlock(hwnd);
    HBITMAP              btm     = NO_IMAGE;
    HWND                 owner   = WinQueryWindow(hwnd, QW_OWNER);
    HPS                  hps;
    HDC                  hdc;
    SWP                  swp;
    BITMAPINFOHEADER2    bmih;
    BITMAPINFOHEADER     bmpData;
    RECTL                rcl;
    HBITMAP              img;
    HBITMAP              msk;
    HBITMAP				 bg;
    POINTL               aptlPoints[4];
    POINTL               p;
    int                  f;
    int                  sz;

    WinQueryWindowPos(hwnd, &swp);

    hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
    hps = GpiCreatePS(hab, hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC);

    /* Make base images */
    GpiQueryBitmapParameters(base, &bmpData);

    memset(&bmih,0, sizeof(BITMAPINFOHEADER2));
    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = bmpData.cx;
    bmih.cy           = bmpData.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 1;
    msk               = GpiCreateBitmap(hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,msk);

    aptlPoints[0].x=0;
    aptlPoints[0].y=0;
    aptlPoints[1].x=aptlPoints[0].x+bmpData.cx-1;
    aptlPoints[1].y=aptlPoints[0].y+bmpData.cy-1;
    aptlPoints[2].x=0;
    aptlPoints[2].y=0;
    aptlPoints[3].x=aptlPoints[2].x+bmpData.cx;
    aptlPoints[3].y=aptlPoints[2].y+bmpData.cy;

    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_PINK);
    GpiWCBitBlt(hps,base,4,aptlPoints,ROP_NOTSRCCOPY,BBO_IGNORE);

    /* Create base image */

    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = bmpData.cx;
    bmih.cy           = bmpData.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;
    img               = GpiCreateBitmap(  hps, &bmih, 0L, NULL, NULL);

    GpiSetBitmap(hps,img);
    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    GpiWCBitBlt( hps,msk,4,aptlPoints,ROP_NOTSRCCOPY,BBO_IGNORE);
    GpiWCBitBlt( hps,base,4,aptlPoints,ROP_SRCAND,BBO_IGNORE);

    /* Draw background */

    memset(&bmih,0, sizeof(BITMAPINFOHEADER2));
    bmih.cbFix        = sizeof(bmih);
    bmih.cx           = swp.cx;
    bmih.cy           = swp.cy;
    bmih.cPlanes      = 1;
    bmih.cBitCount    = 24;

    btm = GpiCreateBitmap(hps,&bmih,0L,NULL,NULL);
    GpiSetBitmap(hps, btm);

    // Ask owner window to draw the background
    icqskin_loadPallete(hps, 0, (const ULONG *) WinSendMsg(hwnd,WMICQ_QUERYPALLETE,0,0));

    rcl.xLeft   =
    rcl.yBottom = 0;
    rcl.xRight  = swp.cx;
    rcl.yTop    = swp.cy;

    bg = icqskin_queryBackground(owner);

    if(!bg || bg == NO_IMAGE)
    {
       WinFillRect(hps, &rcl, ICQCLR_BACKGROUND);
    }
    else
    {
       WinMapWindowPoints(hwnd, owner, (POINTL *) &rcl, 2);
       p.x = p.y = 0;
       WinDrawBitmap(hps, bg, &rcl, &p, CLR_WHITE, CLR_BLACK, DBM_NORMAL);
    }

    GpiSetColor(hps,CLR_WHITE);
    GpiSetBackColor(hps,CLR_BLACK);

    if(swp.cx > bmpData.cx)
    {
       sz = bmpData.cx / 3;
       for(f=sz;f<(swp.cx-(sz*2));f += sz)
          drawTransparent(hps, img, msk, f, 0, sz, bmpData.cy, sz, 0);
       drawTransparent(hps, img, msk, swp.cx-(sz*2), 0, sz, bmpData.cy, sz, 0);
       drawTransparent(hps, img, msk, 0, 0, sz, bmpData.cy, 0, 0);
       drawTransparent(hps, img, msk, swp.cx-sz, 0, sz, bmpData.cy, bmpData.cx-sz, 0);
    }
    else
    {
       sz = swp.cx / 2;
       drawTransparent(hps, img, msk, 0, 0, sz, bmpData.cy, 0, 0);
       drawTransparent(hps, img, msk, sz, 0, sz, bmpData.cy, bmpData.cx-sz, 0);
    }

    // Release resources
    GpiSetBitmap(hps, NULLHANDLE);
    GpiDeleteBitmap(img);
    GpiDeleteBitmap(msk);
    GpiDestroyPS(hps);
    DevCloseDC(hdc);

    return btm;
 }
Пример #29
0
static void
_cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface,
                                           HPS                  hps_begin_paint,
                                           PRECTL               prcl_begin_paint_rect)
{
    HPS hps;
    HDC hdc;
    HAB hab;
    SIZEL sizlTemp;
    HBITMAP hbmpTemp;
    BITMAPINFO2 bmi2Temp;
    POINTL aptlPoints[4];
    int y;
    unsigned char *pchTemp;

    /* To copy pixels from screen to our buffer, we do the following steps:
     *
     * - Blit pixels from screen to a HBITMAP:
     *   -- Create Memory Device Context
     *   -- Create a PS into it
     *   -- Create a HBITMAP
     *   -- Select HBITMAP into memory PS
     *   -- Blit dirty pixels from screen to HBITMAP
     * - Copy HBITMAP lines (pixels) into our buffer
     * - Free resources
     *
     * These steps will require an Anchor Block (HAB). However,
     * WinQUeryAnchorBlock () documentation says that HAB is not
     * used in current OS/2 implementations, OS/2 deduces all information
     * it needs from the TID. Anyway, we'd be in trouble if we'd have to
     * get a HAB where we only know a HPS...
     * So, we'll simply use a fake HAB.
     */

    hab = (HAB) 1; /* OS/2 doesn't really use HAB... */

    /* Create a memory device context */
    hdc = DevOpenDC (hab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
    if (!hdc) {
        return;
    }

    /* Create a memory PS */
    sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft;
    sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom;
    hps = GpiCreatePS (hab,
                       hdc,
                       &sizlTemp,
                       PU_PELS | GPIT_NORMAL | GPIA_ASSOC);
    if (!hps) {
        DevCloseDC (hdc);
        return;
    }

    /* Create an uninitialized bitmap. */
    /* Prepare BITMAPINFO2 structure for our buffer */
    memset (&bmi2Temp, 0, sizeof (bmi2Temp));
    bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2);
    bmi2Temp.cx = sizlTemp.cx;
    bmi2Temp.cy = sizlTemp.cy;
    bmi2Temp.cPlanes = 1;
    bmi2Temp.cBitCount = 32;

    hbmpTemp = GpiCreateBitmap (hps,
                                (PBITMAPINFOHEADER2) &bmi2Temp,
                                0,
                                NULL,
                                NULL);

    if (!hbmpTemp) {
        GpiDestroyPS (hps);
        DevCloseDC (hdc);
        return;
    }

    /* Select the bitmap into the memory device context. */
    GpiSetBitmap (hps, hbmpTemp);

    /* Target coordinates (Noninclusive) */
    aptlPoints[0].x = 0;
    aptlPoints[0].y = 0;

    aptlPoints[1].x = sizlTemp.cx;
    aptlPoints[1].y = sizlTemp.cy;

    /* Source coordinates (Inclusive) */
    aptlPoints[2].x = prcl_begin_paint_rect->xLeft;
    aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom;

    aptlPoints[3].x = prcl_begin_paint_rect->xRight;
    aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop;

    /* Blit pixels from screen to bitmap */
    GpiBitBlt (hps,
               hps_begin_paint,
               4,
               aptlPoints,
               ROP_SRCCOPY,
               BBO_IGNORE);

    /* Now we have to extract the pixels from the bitmap. */
    pchTemp =
        surface->pixels +
        (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 +
        prcl_begin_paint_rect->xLeft*4;
    for (y = 0; y < sizlTemp.cy; y++) {
        /* Get one line of pixels */
        GpiQueryBitmapBits (hps,
                            sizlTemp.cy - y - 1, /* lScanStart */
                            1,                   /* lScans */
                            pchTemp,
                            &bmi2Temp);

        /* Go for next line */
        pchTemp += surface->bitmap_info.cx*4;
    }

    /* Clean up resources */
    GpiSetBitmap (hps, (HBITMAP) NULL);
    GpiDeleteBitmap (hbmpTemp);
    GpiDestroyPS (hps);
    DevCloseDC (hdc);
}
Пример #30
0
// *******************************************************************************                      
// FUNCTION:     DuplicateBitmap                                                                           
//                                                                                                      
// FUNCTION USE: Duplicates a bitmap                                                                        
//                                                                                                      
// DESCRIPTION:  Uses GpiBitBlt to make a copy of a bitmap by bit-bliting the 
//               contents of the source PS containing the bitmap, to the target 
//               presentation space.
//                                                                                                      
// PARAMETERS:   HBITMAP    source bitmap handle to copy                                              
//                                                                                                      
// RETURNS:      HBITMAP    target bitmap handle                                                                                                                      
//                                                                                                      
// HISTORY:                                                                                             
//                                                                                                      
// *******************************************************************************                      
HBITMAP DuplicateBitmap (HBITMAP hbmSource)                                                    
{                                                                                 
 HAB                hab;
 HBITMAP            hbmTarget;                                                        
 HDC                hdcSource;                                                
 HDC                hdcTarget;
 HPS                hpsSource;                                                
 HPS                hpsTarget;
 SIZEL              sizl;         
 POINTL             aptl[3];                                                       
 BOOL               bError = FALSE;
 BITMAPINFOHEADER2  bmp2;                                                           

 // --------------------------------------------------------------------------                      
 // Get an anchor block handle                                                                     
 // --------------------------------------------------------------------------                      
 hab = WinQueryAnchorBlock(HWND_DESKTOP);
                                                                                   
 // --------------------------------------------------------------------------                       
 // Create memory device context handles and presentation space handles                                                                      
 // --------------------------------------------------------------------------                       
 hdcSource = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE);                  
 hdcTarget = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE);                  
                                                                                   
 // --------------------------------------------------------------------------              
 // Set presentation space size                                                            
 // --------------------------------------------------------------------------              
 sizl.cx = 0;                                                         
 sizl.cy = 0;                                                            

 // --------------------------------------------------------------------------            
 // Create our source presentation space                                                           
 // --------------------------------------------------------------------------            
 hpsSource = GpiCreatePS (hab,        
                          hdcSource, 
                          &sizl,                                
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);                    
                                                                                   
 // --------------------------------------------------------------------------                
 // Create our target presentation space                                                      
 // --------------------------------------------------------------------------                
 hpsTarget = GpiCreatePS (hab, 
                          hdcTarget,                  
                          &sizl,
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);   
                                                                                   

 // --------------------------------------------------------------------------                   
 // Initialize the bitmap info header structure                                                        
 // --------------------------------------------------------------------------                                                                                    
// memset(&bmp2, NULL, sizeof(BITMAPINFOHEADER2));           

 // --------------------------------------------------------------------------         
 // Set the size of the structure                                                      
 // --------------------------------------------------------------------------         
 bmp2.cbFix = sizeof (BITMAPINFOHEADER2);                                          

 // --------------------------------------------------------------------------        
 // Get the bitmap information header from the source bitmap                                      
 // --------------------------------------------------------------------------        
 GpiQueryBitmapInfoHeader (hbmSource, &bmp2);                                         

 // --------------------------------------------------------------------------          
 // Create our target bitmap using the bitmap information header from                                                   
 // our source bitmap.
 // --------------------------------------------------------------------------          
 hbmTarget = GpiCreateBitmap (hpsTarget, &bmp2, 0L, NULL, NULL);                         
                                                                                   
 // --------------------------------------------------------------------------                                                 
 // If everything is cool, set the bitmaps into our presentation spaces.                
 // --------------------------------------------------------------------------                   
 if (hbmTarget != GPI_ERROR)                     
  {                                                                            
   GpiSetBitmap (hpsSource, hbmSource);                                              
   GpiSetBitmap (hpsTarget, hbmTarget);                                              
                                                                                   
   aptl[0].x = 0;                                                  
   aptl[0].y = 0;
   aptl[1].x = bmp2.cx;                                                         
   aptl[1].y = bmp2.cy;                                                         
   aptl[2].x = 0;                                                        
   aptl[2].y = 0;
                                                                                   
   // --------------------------------------------------------------------------        
   // Bit blit the contents of the source presentation space into our target           
   // presentation space.  This is how we copy the bitmap from the source to 
   // the target.
   // --------------------------------------------------------------------------        
   bError = GpiBitBlt (hpsTarget,      //  Target presentation space handle                    
                       hpsSource,      //  Source presentation space handle                
                       3L,             //  Number of Points                                
                       aptl,           //  Array of Points                                 
                       ROP_SRCCOPY,    //  Mixing function (source copy)         
                       BBO_IGNORE);    //  Options                                         

   // --------------------------------------------------------------------------                   
   // If we get an error copying from our source PS to our target PS                          
   // set the error flag to TRUE so that we can return GPI_ERROR back                              
   // to the caller.
   // --------------------------------------------------------------------------                   
   if (bError == GPI_ERROR) 
    {
     bError = TRUE;
    }

   // --------------------------------------------------------------------------                
   // If we got a value back from GpiBitBlt reset our error flag since                            
   // bError would be TRUE.
   // --------------------------------------------------------------------------                
   else
    {
     bError = FALSE;
    }
  }                                                                            

 // --------------------------------------------------------------------------            
 // If we get an error creating the bitmap set the bError flag to TRUE      
 // so we can return GPI_ERROR telling the caller that the function failed.
 // --------------------------------------------------------------------------            
 else
  {
   bError = TRUE;
  }

 // --------------------------------------------------------------------------                           
 // Regardless of what happens, we will free all of our graphics engine                            
 // resources by destroying our presentation spaces and device context 
 // handles.
 // --------------------------------------------------------------------------                           
 GpiDestroyPS (hpsSource);                                                           
 GpiDestroyPS (hpsTarget);                                                           
 DevCloseDC (hdcSource);                                                             
 DevCloseDC (hdcTarget);                                                             

 // --------------------------------------------------------------------------              
 // If we get an error trying to duplicate the bitmap, return GPI_ERROR.                   
 // --------------------------------------------------------------------------              
 if (bError) 
  {
   return GPI_ERROR;
  } 

 // --------------------------------------------------------------------------                          
 // If everthing worked like a champ, return the bitmap handle.                                        
 // --------------------------------------------------------------------------                          
 else
  {
   return hbmTarget;                                                                   
  }
}