Ejemplo n.º 1
0
/****************************************************************************
   Main Program start
*****************************************************************************/
int main()
{
    HMQ   hmq;
    QMSG  qmsg;

    hab = WinInitialize (0);
    hmq = WinCreateMsgQueue (hab, 0);

    hWndFrame = WinLoadDlg (HWND_DESKTOP, HWND_DESKTOP,
        MainDlgProc, 0, IDD_CLOCK,NULL);
    TitleDefProc = WinSubclassWindow(WinWindowFromID(hWndFrame, FID_TITLEBAR),
                   (PFNWP)TitleBarProc );
    SysMenuDefProc = WinSubclassWindow(WinWindowFromID(hWndFrame, FID_SYSMENU),
                   (PFNWP)SysMenuProc );

    SysMenuButton = WinLoadPointer (HWND_DESKTOP, 0, IDD_CLOCK);
    WinQueryPointerInfo(SysMenuButton,&PointerInfo);
    WinSendMsg (hWndFrame, WM_SETICON, (MPARAM)SysMenuButton, NULL);


    while (WinGetMsg (hab, &qmsg, 0, 0, 0))
        WinDispatchMsg (hab, &qmsg);

    WinDestroyWindow (hWndFrame);
    WinDestroyMsgQueue (hmq);
    WinTerminate (hab);
    return (0);
}
Ejemplo n.º 2
0
// static
QIcon QPixmap::fromPmHPOINTER(HPOINTER hpointer, QPixmap *pixmap,
                              QPixmap *pixmapMini)
{
    QIcon res;

    if (hpointer == NULLHANDLE)
        return res;

    POINTERINFO info = { 0 };
    if (!WinQueryPointerInfo(hpointer, &info))
        return res;

    QPixmap pm = fromPmHBITMAP(info.hbmColor, info.hbmPointer);
    if (!pm.isNull())
        res.addPixmap(pm);

    QPixmap pmMini = fromPmHBITMAP(info.hbmMiniColor, info.hbmMiniPointer);
    if (!pmMini.isNull())
        res.addPixmap(pmMini);

    if (pixmap)
        *pixmap = pm;
    if (pixmapMini)
        *pixmapMini = pmMini;

    return res;
}
Ejemplo n.º 3
0
void Window::getCursorExtent( int &width, int &height )
{
	POINTERINFO pInfo;

	WinQueryPointerInfo( WinQueryPointer( HWND_DESKTOP ), &pInfo );
	width = pInfo.xHotspot;
	height = /*WinQuerySysValue( HWND_DESKTOP, SV_CYPOINTER ) - */pInfo.yHotspot;
}
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;
}
Ejemplo n.º 5
0
static HPOINTER combineTwoCursors(LONG idOver, LONG idUnder)
{
    HPOINTER hptr = NULLHANDLE;

    POINTERINFO piOver, piUnder;
    HPOINTER hOver = WinQuerySysPointer(HWND_DESKTOP, idOver, FALSE);
    WinQueryPointerInfo(hOver, &piOver);
    HPOINTER hUnder = WinQuerySysPointer(HWND_DESKTOP, idUnder, FALSE);
    WinQueryPointerInfo(hUnder, &piUnder);
    if (piOver.hbmColor) {
        HPS hpsPtr, hpsTmp, hpsMask;
        HBITMAP hbmPtr, hbmTmp, hbmMask;
        qt_alloc_ps_with_bitmap(32, 32, false, hpsPtr, hbmPtr);
        qt_alloc_ps_with_bitmap(32, 32, false, hpsTmp, hbmTmp);
        qt_alloc_ps_with_bitmap(32, 64, true, hpsMask, hbmMask);
        // copy the overlying pointer
        POINTL ptls[] = { { 0, 0 }, { 31, 31 }, { 0, 0 }, { 32, 32 } };
        GpiWCBitBlt(hpsTmp, piOver.hbmColor, 4, ptls, ROP_SRCCOPY, BBO_IGNORE);
        // make its transparent pixels black
        ptls[2].y += 32; ptls[3].y += 32;
        GpiSetColor(hpsTmp, CLR_TRUE);
        GpiSetBackColor(hpsTmp, CLR_FALSE);
        GpiWCBitBlt(hpsTmp, piOver.hbmPointer, 4, ptls, 0x22, BBO_IGNORE);
        // copy the underlying pointer
        ptls[2].y -= 32; ptls[3].y -= 32;
        GpiWCBitBlt(hpsPtr, piUnder.hbmColor, 4, ptls, ROP_SRCCOPY, BBO_IGNORE);
        // make non-transparent pixels from the overlying pointer black
        ptls[2].y += 32; ptls[3].y += 32;
        GpiSetColor(hpsPtr, CLR_TRUE);
        GpiSetBackColor(hpsPtr, CLR_FALSE);
        GpiWCBitBlt(hpsPtr, piOver.hbmPointer, 4, ptls, ROP_SRCAND, BBO_IGNORE);
        // put the overlying pointer there
        ptls[2].y -= 32; ptls[3].y -= 32;
        ptls[1].x ++; ptls[1].y ++;
        GpiBitBlt(hpsPtr, hpsTmp, 4, ptls, ROP_SRCPAINT, BBO_IGNORE);
        // copy both underlying pointer's masks
        ptls[1].x --; ptls[1].y --;
        ptls[1].y += 32; ptls[3].y += 32;
        GpiWCBitBlt(hpsMask, piUnder.hbmPointer, 4, ptls, ROP_SRCCOPY, BBO_IGNORE);
        // add overlying pointer's XOR mask
        ptls[1].y -= 32; ptls[3].y -= 32;
        GpiWCBitBlt(hpsMask, piOver.hbmPointer, 4, ptls, ROP_SRCPAINT, BBO_IGNORE);
        // add overlying pointer's AND mask
        ptls[0].y += 32; ptls[2].y += 32;
        ptls[1].y += 32; ptls[3].y += 32;
        GpiWCBitBlt(hpsMask, piOver.hbmPointer, 4, ptls, ROP_SRCAND, BBO_IGNORE);
        // create the new pointer
        GpiSetBitmap(hpsPtr, NULLHANDLE);
        GpiSetBitmap(hpsMask, NULLHANDLE);
        piOver.hbmColor = hbmPtr;
        piOver.hbmPointer = hbmMask;
        piOver.hbmMiniColor = NULLHANDLE;
        piOver.hbmMiniPointer = NULLHANDLE;
        hptr = WinCreatePointerIndirect(HWND_DESKTOP, &piOver);
        qt_free_ps_with_bitmap(hpsMask,  hbmMask);
        qt_free_ps_with_bitmap(hpsTmp,  hbmTmp);
        qt_free_ps_with_bitmap(hpsPtr,  hbmPtr);
    } else {
        HPS hps;
        HBITMAP hbm;
        qt_alloc_ps_with_bitmap(32, 64, true, hps, hbm);
        POINTL ptls[] = { { 0, 0 }, { 31, 63 }, { 0, 0 }, { 32, 64 } };
        // make a copy of the underlying pointer
        GpiWCBitBlt(hps, piUnder.hbmPointer, 4, ptls, ROP_SRCCOPY, BBO_IGNORE);
        // combine AND masks
        ptls[0].y += 32; ptls[2].y += 32;
        GpiWCBitBlt(hps, piOver.hbmPointer, 4, ptls, ROP_SRCAND, BBO_IGNORE);
        // apply the overlying AND mask to the underlying XOR mask
        ptls[0].y -= 32; ptls[1].y -= 32;
        GpiWCBitBlt(hps, piOver.hbmPointer, 4, ptls, ROP_SRCAND, BBO_IGNORE);
        // apply the overlying XOR mask to the underlying XOR mask
        ptls[2].y -= 32; ptls[3].y -= 32;
        GpiWCBitBlt(hps, piOver.hbmPointer, 4, ptls, ROP_SRCINVERT, BBO_IGNORE);
        // create the new pointer
        GpiSetBitmap(hps, 0);
        hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE,
                                piOver.xHotspot, piOver.yHotspot);
        qt_free_ps_with_bitmap(hps, hbm);
    }

    Q_ASSERT(hptr);
    return hptr;
}