static BOOL LoadCursorRes (void)
{
    int number;
    int i;
    PCURSOR tempcsr;
    char *temp;
    char szValue [12];

    __mg_csrimgsize = GAL_GetBoxSize (__gal_screen, CURSORWIDTH, CURSORHEIGHT, &__mg_csrimgpitch);

    if (GetMgEtcValue (CURSORSECTION, "cursornumber", szValue, 10) < 0)
        goto error;

    number = atoi (szValue);
    if (number < 0) goto error;
    number = number < (MAX_SYSCURSORINDEX + 1) ? number : (MAX_SYSCURSORINDEX + 1);

    // realloc for shared resource
    mgSharedRes = realloc (mgSharedRes, mgSizeRes + __mg_csrimgsize +
                    number * (sizeof (HCURSOR) + sizeof (CURSOR) + 2*__mg_csrimgsize));
    if (mgSharedRes == NULL) {
        perror ("realloc shared memory for system cursor");
        return FALSE;
    }

    // set cursor number
    ((PG_RES)mgSharedRes)->csrnum    = number;
    // set cursor data offset
    ((PG_RES)mgSharedRes)->svdbitsoffset = mgSizeRes;
    mgSizeRes += __mg_csrimgsize;
    ((PG_RES)mgSharedRes)->csroffset = mgSizeRes;

    // pointer to begin of cursor struct, 
    // and reserve a space for handles for system cursors.
    temp = (char*)mgSharedRes + mgSizeRes + sizeof (PCURSOR) * number;

    for (i = 0; i < number; i++) {
        if ( !(tempcsr = sysres_load_system_cursor (i)) )
            goto error;

        memcpy (temp, tempcsr, sizeof(CURSOR));        
        temp += sizeof(CURSOR);
        memcpy (temp, tempcsr->AndBits, __mg_csrimgsize);
        temp += __mg_csrimgsize; 
        memcpy (temp, tempcsr->XorBits, __mg_csrimgsize);
        temp += __mg_csrimgsize; 
        free (tempcsr->AndBits);
        free (tempcsr->XorBits);
        free (tempcsr);
    }

    mgSizeRes += (sizeof (HCURSOR) + sizeof(CURSOR) + 2 * __mg_csrimgsize) * number;
    return TRUE;

error:
    return FALSE;
}
Beispiel #2
0
BOOL GUIAPI CreateCaret (HWND hWnd, PBITMAP pBitmap, int nWidth, int nHeight)
{
    PMAINWIN pWin;

    pWin = (PMAINWIN)hWnd;

    if (!pWin->pCaretInfo) {
        if (!(pWin->pCaretInfo = malloc (sizeof (CARETINFO))))
            return FALSE;
        
        pWin->pCaretInfo->pBitmap = pBitmap;
        if (pBitmap) {
            nWidth  = pBitmap->bmWidth;
            nHeight = pBitmap->bmHeight;
        }
        pWin->pCaretInfo->nWidth  = nWidth;
        pWin->pCaretInfo->nHeight = nHeight;
#ifdef _USE_NEWGAL
        pWin->pCaretInfo->caret_bmp.bmType = BMP_TYPE_NORMAL;
        pWin->pCaretInfo->caret_bmp.bmWidth = nWidth;
        pWin->pCaretInfo->caret_bmp.bmHeight = nHeight;
        pWin->pCaretInfo->caret_bmp.bmBytesPerPixel = BYTESPERPHYPIXEL;

        pWin->pCaretInfo->nBytesNr = GAL_GetBoxSize (__gal_screen, 
                        nWidth, nHeight, &pWin->pCaretInfo->caret_bmp.bmPitch);
#else
        pWin->pCaretInfo->nEffWidth  = nWidth;
        pWin->pCaretInfo->nEffHeight = nHeight;

        pWin->pCaretInfo->nBytesNr = nWidth * nHeight * BYTESPERPHYPIXEL;
#endif
        pWin->pCaretInfo->pNormal = malloc (pWin->pCaretInfo->nBytesNr);
        pWin->pCaretInfo->pXored  = malloc (pWin->pCaretInfo->nBytesNr);

        if (pWin->pCaretInfo->pNormal == NULL ||
            pWin->pCaretInfo->pXored == NULL) {
            free (pWin->pCaretInfo);
            pWin->pCaretInfo = NULL;
            return FALSE;
        }

        pWin->pCaretInfo->x = pWin->pCaretInfo->y = 0;
        
        pWin->pCaretInfo->fBlink  = FALSE;
        pWin->pCaretInfo->fShow   = FALSE;
        
        pWin->pCaretInfo->hOwner  = hWnd;
        pWin->pCaretInfo->uTime   = 500;
    }

    SendMessage (HWND_DESKTOP, MSG_CARET_CREATE, (WPARAM)hWnd, 0);

    return TRUE;
}