// static HPOINTER QPixmap::toPmHPOINTER(const QIcon &icon, bool isPointer, int hotX, int hotY, bool embedRealAlpha, bool isMini) { if (icon.isNull()) return NULLHANDLE; // get the system icon size int w = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CXPOINTER : SV_CXICON); int h = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CYPOINTER : SV_CYICON); if (!isPointer && isMini) { w = w / 2; h = h / 2; } // obtain the closest (but never larger) icon size we have QSize size = icon.actualSize(QSize(w, h)); QPixmap pm = icon.pixmap(size); if (pm.isNull()) return NULLHANDLE; // if we got a smaller pixmap then center it inside the box matching the // system size instead of letting WinCreatePointerIndirect() scale (this // covers a usual case when we get 32/16 px pixmaps on a 120 DPI system // where the icon size is 40/20 px respectively): scaling such small images // looks really ugly. if (!pm.isNull() && (pm.width() < w || pm.height() < h)) { Q_ASSERT(pm.width() <= w && pm.height() <= h); QPixmap pmNew(w, h); pmNew.fill(Qt::transparent); QPainter painter(&pmNew); int dx = (w - pm.width()) / 2; int dy = (h - pm.height()) / 2; painter.drawPixmap(dx, dy, pm); pm = pmNew; hotX += dx; hotY += dy; } POINTERINFO info; info.fPointer = isPointer; info.xHotspot = hotX; info.yHotspot = pm.height() - hotY - 1; info.hbmColor = pm.toPmHBITMAP(&info.hbmPointer, embedRealAlpha); info.hbmMiniPointer = NULLHANDLE; info.hbmMiniColor = NULLHANDLE; HPOINTER hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &info); GpiDeleteBitmap(info.hbmPointer); GpiDeleteBitmap(info.hbmColor); return hIcon; }
//cleanup resources generated by CBZInit BOOL CBZDestroy(HWND hwnd, PVOID pData) { PLUGINSHARE *pPluginData; pPluginData = (PLUGINSHARE *) pData; if (pPluginData->hbmActive != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActive); if (pPluginData->hbmActiveMask != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveMask); if (pPluginData->hbmInactive != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactive); if (pPluginData->hbmInactiveMask != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveMask); if (pPluginData->hbmSelectedActive != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmSelectedActive); if (pPluginData->hbmSelectedActiveMask != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmSelectedActiveMask); if (pPluginData->hbmSelectedInactive != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmSelectedInactive); if (pPluginData->hbmSelectedInactiveMask != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmSelectedInactiveMask); DosFreeMem(pPluginData); return (TRUE); }
/*@ XBitmap::Load(const char* filename, XBitmapFilter * params, BOOL releaseParams) @group loading a bitmap @remarks Load a bitmap from a file. <P><I>If this method is used, GBM.DLL and OLLGLIB.DLL must be in the LIBPATH.</I> <P>Due a bug (?) in OS/2-GPI you should specify params->cBitCount = BFP_BPP_TRUECOLOR if you want to modify or resave the bitmap. @parameters <t 'ø' c=2> øchar * fileName øfilename of the file to load øXBitmapFilter * params øfiletype specific filter informations. An initialized structure has to be created by XBitmap :: GetImportFilterStruct () or XGLibFileDialog. (default is NULL) øBOOL releaseParams øfilter informations will be released after usages <\t> @exceptions If the method fails to create a new bitmap an exception of the type XException is thrown. */ void XBitmap :: Load (const char* filename, XBitmapFilter* params, BOOL releaseParams) { if (hbm) GpiDeleteBitmap(hbm); hbm = NULLHANDLE; XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB"); XGLibProcIO* func = (XGLibProcIO*) lib->LoadFunction ("OOL_GLIB_IMP"); DosSleep(100); if (NULL != func) { if (owner) hps = WinGetPS (owner->GetHandle()); ULONG rc; if (NULL == params) params = GetImportFilterStruct (filename); params->hps = hps; params->hbm = hbm; params->hab = XApplication :: GetApplication ()->GetAnchorBlock (); if (BFE_OK != (rc = func (filename, __XBMFProfile__, params, 0))) { if (releaseParams) ReleaseFilterStruct (params); OOLThrow (GetLastErrorMessage (lib, &rc, params), rc); } hbm = params->hbm; if (releaseParams) ReleaseFilterStruct (params); lib->UnLoadFunction ((PFNWP) func); } else { if (releaseParams) ReleaseFilterStruct (params); ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ()); OOLThrow("Could not load function \"OOL_GLIB_IMP\" from library \"OOLGLIB.DLL\".", error); } delete lib; XSize s; GetDimensions(&s); width = cx = s.GetWidth(); height = cy = s.GetHeight(); }
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); } } }
void QFObjectRenderer::copyFrame() { IClipboard clipboard(window_p->handle()); PBYTE frameBuffer; ULONG scanLineBytes, scanLines; BITMAPINFOHEADER2 bmp = {0}; BITMAPINFOHEADER2 bmpInfo; HBITMAP hbm; LONG errorCode; errorCode = DiveBeginImageBufferAccess(dive, frame[currentColumn][currentRow], &frameBuffer, &scanLineBytes, &scanLines); bmp.cbFix = sizeof(BITMAPINFOHEADER2); bmp.cx = movieSize().width(); bmp.cy = movieSize().height(); bmp.cPlanes = 1; bmp.cBitCount = 24; bmp.ulCompression = BCA_UNCOMP; bmp.cbImage = scanLineBytes * scanLines; bmp.usRecording = BRA_BOTTOMUP; /* Must be BRA_BOTTOMUP. */ bmp.usRendering = BRH_NOTHALFTONED; /* Not used. */ bmp.ulColorEncoding = BCE_RGB; bmpInfo = bmp; IGraphicContext context; hbm = GpiCreateBitmap(context.handle(), &bmp, CBM_INIT, frameBuffer, (PBITMAPINFO2)&bmpInfo); clipboard.setBitmap(hbm); GpiDeleteBitmap(hbm); errorCode = DiveEndImageBufferAccess(dive, frame[currentColumn][currentRow]); }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static HBITMAP hbm ; HPS hps ; RECTL rcl ; switch (msg) { case WM_CREATE: hps = WinGetPS (hwnd) ; hbm = GpiLoadBitmap (hps, 0, IDB_HELLO, 0L, 0L) ; WinReleasePS (hps) ; return 0 ; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ; GpiErase (hps) ; WinQueryWindowRect (hwnd, &rcl) ; if (hbm) WinDrawBitmap (hps, hbm, NULL, (PPOINTL) &rcl, CLR_BACKGROUND, CLR_NEUTRAL, DBM_STRETCH) ; WinEndPaint (hps) ; return 0 ; case WM_DESTROY: if (hbm) GpiDeleteBitmap (hbm) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
LONG XBitmap::SetData(const BITMAPINFOHEADER2 * p, const LONG offset) { LONG cScans; BITMAPINFOHEADER2 *data; LONG size = (((((BITMAPINFOHEADER2 *) p)->cBitCount * ((BITMAPINFOHEADER2 *) p)->cx) + 31) / 32) * 4 * ((BITMAPINFOHEADER2 *) p)->cPlanes * ((BITMAPINFOHEADER2 *) p)->cy; data = (PBITMAPINFOHEADER2) malloc(size); memcpy(data, p, size); if (data->cbFix == sizeof(BITMAPINFOHEADER)) cScans = (ULONG) ((PBITMAPINFOHEADER) data)->cy; else cScans = data->cy; if (hbm != 0) GpiDeleteBitmap(hbm); hbm = GpiCreateBitmap(hps, data, CBM_INIT, (PBYTE) p + offset, (PBITMAPINFO2) data); if (hbm == GPI_ERROR) OOLThrow("error creating bitmap", 3); free(data); return 0; }
XBitmap :: ~XBitmap() { GpiDeleteBitmap(hbm); GpiDestroyPS(hps); DevCloseDC(hdc); hbm = 0; hps = 0; hdc = 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 }
QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h) { QPixmap pm; if (w == 0 || h == 0) return pm; RECTL rcl; if (!WinQueryWindowRect(winId, &rcl)) return pm; if (w < 0) w = rcl.xRight; if (h < 0) h = rcl.yTop; // flip y coordinate y = rcl.yTop - (y + h); HPS hps = qt_alloc_mem_ps(w, h); if (hps == NULLHANDLE) return pm; HBITMAP hbm = NULLHANDLE; // bitmap header + 2 palette entries (for the mask) BITMAPINFOHEADER2 bmh; bmh.cbFix = sizeof(BITMAPINFOHEADER2); // create the uninitialized bitmap to hold window pixels bmh.cx = w; bmh.cy = h; bmh.cPlanes = 1; bmh.cBitCount = 32; hbm = GpiCreateBitmap(hps, &bmh, 0, 0, 0); if (hbm != NULLHANDLE) { GpiSetBitmap(hps, hbm); HPS hpsWin = WinGetPS(winId); if (hpsWin != NULLHANDLE) { POINTL pnts[] = { {0, 0}, {w, h}, {x, y} }; if (GpiBitBlt(hps, hpsWin, 3, pnts, ROP_SRCCOPY, BBO_IGNORE) != GPI_ERROR) { GpiSetBitmap(hps, NULLHANDLE); pm = fromPmHBITMAP(hbm); } WinReleasePS(hpsWin); } GpiDeleteBitmap(hbm); } qt_free_mem_ps(hps); return pm; }
static void destroy(HWND hwnd) { SLIDERDATA *cfg = WinQueryWindowPtr(hwnd,0); int f; if(!cfg) return; if(cfg->bg) GpiDeleteBitmap(cfg->bg); for(f=0;f<BITMAPS_SLIDER;f++) { if(cfg->btm[f].image) GpiDeleteBitmap(cfg->btm[f].image); if(cfg->btm[f].masc) GpiDeleteBitmap(cfg->btm[f].masc); } free(cfg); }
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); }
//cleanup resources generated by CBZInit BOOL CBZDestroy(HWND hwnd, PVOID pData) { PLUGINSHARE *pPluginData; pPluginData = (PLUGINSHARE *) pData; //Restore the Original Images. #if 0 WinSendMsg(hwnd, MM_SETITEMHANDLE, MPFROMSHORT(SC_RESTORE), MPFROMLONG(pPluginData->hbmOldRestore) ); WinSendMsg(hwnd, MM_SETITEMHANDLE, MPFROMSHORT(SC_MAXIMIZE), MPFROMLONG(pPluginData->hbmOldMaximize) ); WinSendMsg(hwnd, MM_SETITEMHANDLE, MPFROMSHORT(SC_HIDE), MPFROMLONG(pPluginData->hbmOldHide) ); WinSendMsg(hwnd, MM_SETITEMHANDLE, MPFROMSHORT(SC_MINIMIZE), MPFROMLONG(pPluginData->hbmOldMinimize) ); WinSendMsg(hwnd, MM_SETITEMHANDLE, MPFROMSHORT(SC_CLOSE), MPFROMLONG(pPluginData->hbmOldClose) ); #endif if (pPluginData->hbmActiveMinimize != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveMinimize); if (pPluginData->hbmInactiveMinimize != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveMinimize); if (pPluginData->hbmActiveMaximize != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveMaximize); if (pPluginData->hbmInactiveMaximize != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveMaximize); if (pPluginData->hbmActiveRestore != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveRestore); if (pPluginData->hbmInactiveRestore != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveRestore); if (pPluginData->hbmActiveClose != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveClose); if (pPluginData->hbmInactiveClose != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveClose); if (pPluginData->hbmActiveHide != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmActiveHide); if (pPluginData->hbmInactiveHide != NULLHANDLE) GpiDeleteBitmap(pPluginData->hbmInactiveHide); DosFreeMem(pPluginData); return (TRUE); }
void DisplayVbuf(HPS hpsBuffer, RECTL rect, int isChange) { POINTL aptl[4]; LONG lhits; /* Create a bit map that is compatible with the display. */ if (isChange) { if (hbm) GpiDeleteBitmap(hbm); hbm = GpiCreateBitmap(hpsDesktop, &bmp, CBM_INIT, (PBYTE) pBmpBuffer, pbmi); GpiSetBitmap(hpsDesktop,hbm); GpiSetBitmapBits(hpsDesktop, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi); //????? } else { // GpiSetBitmap(hpsBuffer,hbm); // ii = GpiSetBitmapBits(hpsBuffer, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi); GpiSetBitmap(hpsDesktop,hbm); GpiSetBitmapBits(hpsDesktop, 0,bmp.cy,(PBYTE) pBmpBuffer, pbmi); } aptl[0].x = rect.xLeft; /* Lower-left corner of destination rectangle */ aptl[0].y = rect.yBottom; /* Lower-left corner of destination rectangle */ aptl[1].x = rect.xRight; /* Upper-right corner of destination rectangle */ aptl[1].y = rect.yTop; /* Upper-right corner of destination rectangle */ /* Source-rectangle dimensions (in device coordinates) */ aptl[2].x = 0; /* Lower-left corner of source rectangle */ aptl[2].y = 0; /* Lower-left corner of source rectangle */ aptl[3].x = bmp.cx; // bmp.cx; aptl[3].y = bmp.cy; // bmp.cy; pbmi->cy = bmp.cy; /* >>>>>>>>>>>>>>>>>>>>>>>>>>> */ //lhits = GpiBitBlt(hpsBuffer , hpsMem, // 3, /* 3-source rect=dest rect 4 Number of points in aptl */ // aptl, ROP_SRCCOPY, BBO_IGNORE/* | BBO_PAL_COLORS*/ ); // if(ii != GPI_OK) // { ERRORID errid; // errid = WinGetLastError(hab); // ierr++; // } GpiSetBitmap(hpsDesktop,0); // rc = GpiDeleteBitmap(hbm); }
VOID GRAPHBOARD::DrawPMMark( const HPS hps, const char Row, const char Col ) { POINTL Point; ULONG Bitmap; HBITMAP hbm; if( GetDiscovered( Row, Col ) != -1 ) return; if( GetMarked( Row, Col ) ) Bitmap = BMP_UNMARK; else Bitmap = BMP_MARK; Point.x = LowerLeftPlace.x + (Col - 1)*dist - dist/6; Point.y = LowerLeftPlace.y + (Row - 1)*dist - dist/6; hbm = GpiLoadBitmap( hps, (HMODULE)NULL, Bitmap, dist/3, dist/3); // if( hbm == NULLHANDLE ) DosBeep( 500, 150 ); // if( !(WinDrawBitmap( hps, hbm, NULL, &Point, 0, 0, DBM_NORMAL ) )) // DosBeep( 1000, 150 ); WinDrawBitmap(hps, hbm, NULL, &Point, 0, 0, DBM_NORMAL); GpiDeleteBitmap( hbm ); // releases the bitmap-handle ToggleMarked( Row, Col ); }
void XBitmap::Load( const ULONG id, const XResourceLibrary * lib) { if (hbm) GpiDeleteBitmap(hbm); if (owner && hps == 0) hps = WinGetPS(owner->GetHandle()); hbm = GpiLoadBitmap(hps, lib->GetModuleHandle(), id, 0, 0); if (hbm == GPI_ERROR) { ULONG error = WinGetLastError(XApplication::GetApplication()->GetAnchorBlock()); OOLThrow("couldnït load bitmap", error); } XSize s; GetDimensions(&s); width = cx = s.GetWidth(); height = cy = s.GetHeight(); }
/*@ XBitmap::LoadBMP(const char* filename) @group loading a bitmap @remarks Load a bitmap from a file. This method works faster than Load() but can only load bitmpas in OS2-BMP format @parameters char * fileName filename of the file to load @exceptions If the method fails to create a new bitmap an exception of the type XException is thrown. */ void XBitmap :: LoadBMP(const char* filename) { if (hbm) GpiDeleteBitmap(hbm); hbm = 0; XFile file; PBITMAPFILEHEADER p; if (file.Open(filename, XFILE_FAIL_IF_NEW | XFILE_OPEN_EXISTING, XFILE_READONLY, XFILE_SHARE_DENYNONE ) == 0) { XFileInfo info; file.GetFileInfo(&info); file.Seek(0, XFILE_BEGIN); p = (PBITMAPFILEHEADER) malloc(info.GetFileSize()); file.Read(p, info.GetFileSize()); file.Close(); } else OOLThrow( "couldnït open file!", -1); if (owner ) { hps = WinGetPS(owner->GetHandle()); hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &p->bmp, CBM_INIT, (PBYTE) p + p->offBits, (PBITMAPINFO2) &p->bmp); if(hbm == 0) OOLThrow("error creating bitmap", 3); } else SetData((BITMAPINFOHEADER2 *) &p->bmp, p->offBits); free(p); XSize s; GetDimensions(&s); width = cx = s.GetWidth(); height = cy = s.GetHeight(); if (hbm == GPI_ERROR) { ULONG error = WinGetLastError(XApplication::GetApplication()->GetAnchorBlock()); OOLThrow("couldnït load bitmap", error); } return; }
// manages changes in size VOID WndResize( const HWND hwnd ) { wcprintf("WndResize"); RECTL rWindow; LONG cyHeight, cxWidth; BITMAPINFOHEADER bmp; if( (hbmGlob = GpiSetBitmap( hpsBufferGlob, NULLHANDLE )) != NULLHANDLE ){ wcprintf("wndresize: there was an old bitmap"); GpiDeleteBitmap( hbmGlob ); // delete old stuff } else wcprintf("wndresize: there was no old bitmap"); // build the bitmap: WinQueryWindowRect( hwnd, &rWindow ); cxWidth = rWindow.xRight - rWindow.xLeft;// - 2; cyHeight = rWindow.yTop - rWindow.yBottom; // - 2; wcprintf("wndResize: Breite: %d, H”he: %d", rWindow.xRight, rWindow.yTop ); memset(&bmp, 0, sizeof(BITMAPINFOHEADER)); bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitCount; hbmGlob = GpiCreateBitmap(hpsBufferGlob, (PBITMAPINFOHEADER2)&bmp, 0L, NULL, NULL); if( hbmGlob == GPI_ERROR ) DosBeep( 100, 500); GpiSetBitmap( hpsBufferGlob, hbmGlob); // calculate the size // if( !GpiSetPageViewport(hpsGlob, &rWindow) ) // wcprintf("error 1"); return; if( !GpiSetPageViewport(hpsBufferGlob, &rWindow) ) wcprintf("error 2"); }
VOID GRAPHBOARD::DrawPMPlace( const HPS hps, const char Row, const char Col, INT Value, const BOOL fSwap ) { POINTL Point; ULONG Bitmap; HBITMAP hbm; Point.x = LowerLeftPlace.x + (Col - 1)*dist - dist/3; Point.y = LowerLeftPlace.y + (Row - 1)*dist - dist/3; if( !fSwap ){ if( Value >= 50 ) Value -= 50; else if(Value <= 4 ) Value += 50; } // fSwap indicates if a number // will be swapped into a circle or vice versa if ( Value >= 50 ) { // a number has already been found and will be // replaced by a circle now Bitmap = BMP_FCIRCLE; SetDiscovered( Row, Col, (SHORT)(Value - 50) ); } else { switch( Value ){ case 0: Bitmap = BMP_F0; break; case 1: Bitmap = BMP_F1; break; case 2: Bitmap = BMP_F2; break; case 3: Bitmap = BMP_F3; break; case 4: Bitmap = BMP_F4; break; default: Bitmap = BMP_SHIP; } if( Value != GetShipNumber() + 10 ) SetDiscovered( Row, Col, (SHORT)(Value + 50) ); } hbm = GpiLoadBitmap( hps, (HMODULE)NULL, Bitmap, dist*2/3, dist*2/3); // if( hbm == NULLHANDLE ) DosBeep( 500, 150 ); // if( !(WinDrawBitmap( hps, hbm, NULL, &Point, 0, 0, DBM_NORMAL ) )) // DosBeep( 1000, 150 ); WinDrawBitmap(hps, hbm, NULL, &Point, 0, 0, DBM_NORMAL); GpiDeleteBitmap( hbm ); // releases the bitmap-handle }
void QPixmap::setMask( const QBitmap &newmask ) { const QPixmap *tmp = &newmask; // dec cxx bug if ( (data == tmp->data) || ( newmask.handle() && newmask.handle() == handle() ) ) { QPixmap m = tmp->copy( TRUE ); setMask( *((QBitmap*)&m) ); data->selfmask = TRUE; // mask == pixmap return; } if ( newmask.isNull() ) { // reset the mask if (data->mask) { detach(); data->selfmask = FALSE; delete data->mask; data->mask = 0; #if defined (Q_WS_PM) if ( data->maskedHbm ) { GpiDeleteBitmap( data->maskedHbm ); data->maskedHbm = 0; } #endif } #if defined (Q_WS_PM) if ( data->hasRealAlpha ) { detach(); data->hasRealAlpha = FALSE; if ( data->realAlphaBits ) { delete[] data->realAlphaBits; data->realAlphaBits = 0; } } #endif return; } detach(); data->selfmask = FALSE; if ( newmask.width() != width() || newmask.height() != height() ) { #if defined(QT_CHECK_RANGE) qWarning( "QPixmap::setMask: The pixmap and the mask must have " "the same size" ); #endif return; } #if defined(Q_WS_MAC) || (defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE)) // when setting the mask, we get rid of the alpha channel completely delete data->alphapm; data->alphapm = 0; #endif // Q_WS_X11 && !QT_NO_XFTFREETYPE #if defined (Q_WS_PM) if ( data->hasRealAlpha ) { data->hasRealAlpha = FALSE; if ( data->realAlphaBits ) { delete[] data->realAlphaBits; data->realAlphaBits = 0; } } if ( data->maskedHbm ) { GpiDeleteBitmap( data->maskedHbm ); data->maskedHbm = 0; } #endif delete data->mask; QBitmap* newmaskcopy; if ( newmask.mask() ) newmaskcopy = (QBitmap*)new QPixmap( tmp->copy( TRUE ) ); else newmaskcopy = new QBitmap( newmask ); #ifdef Q_WS_X11 newmaskcopy->x11SetScreen( x11Screen() ); #endif data->mask = newmaskcopy; }
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); }
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); }
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; }
/****************************************************************\ * *-------------------------------------------------------------- * * Name: ClkSize() * * Purpose:When the window has been sized, we calculate a page * rectangle which: (a) fills the window rectangle in either * the x or y dimension, (b) appears square, and (c) is centered * in the window rectangle * Usage: * * Method: * - * * - * - * * - * - * * Returns: * * \****************************************************************/ VOID ClkSize (HWND hwnd) { RECTL rclWindow; SIZEF sizef; LONG cxSquare, cySquare, cxEdge, cyEdge; LONG cyHeight; LONG cxWidth; HBITMAP hbm; BITMAPINFOHEADER bmp; /* * First get rid of any buffer bitmap already there. */ hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE); if (hbm != NULLHANDLE) GpiDeleteBitmap (hbm); /* * Get the width and height of the window rectangle. */ WinQueryWindowRect (hwnd, &rclWindow); cxWidth = rclWindow.xRight - rclWindow.xLeft - 2; cyHeight = rclWindow.yTop - rclWindow.yBottom - 2; /* * Now create a bitmap the size of the window. */ bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitcount; hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp, 0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL); GpiSetBitmap (hpsBuffer, hbm); /* * Assume the size of the page rectangle is constrained in the y * dimension,compute the x size which would make the rectangle appear * square, then check the assumption and do the reverse calculation * if necessary. */ cySquare = cyHeight - 2; cxSquare = ( cyHeight * cxRes ) / cyRes; if (cxWidth < cxSquare) { cxSquare = cxWidth - 2; cySquare = (cxWidth * cyRes) / cxRes; } /* * Fill in the page rectangle and set the page viewport. */ cxEdge = (cxWidth - cxSquare ) / 2; cyEdge = (cyHeight - cySquare ) / 2; rclPage.xLeft = cxEdge; rclPage.xRight = cxWidth - cxEdge; rclPage.yBottom = cyEdge; rclPage.yTop = cyHeight - cyEdge; /* * Determine where to put the date. If we have room under the clock, we * put it there. If we have more room on the left we put it there. If we * have more room in the midlle, it goes there. */ if (cp.usDispMode & DM_DATE) { vclrDate[SURFACE] = vclrBG[SHADE]; vclrDate[LIGHT] = vclrBG[LIGHT]; vclrDate[SHADE] = vclrBG[SHADE]; vclrDate[BACKGROUND] = vclrBG[SURFACE]; if (cyHeight > (cySquare*6/5)) { /*Goes under*/ vmatlfDateTrans.lM31 = (LONG)15; /*Horizontal*/ vmatlfDateTrans.lM32 = -(LONG)17; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0x8000); vmatlfDateScale.fxM22 = MAKEFIXED(2,0x8000); rclPage. yTop += cyEdge; rclPage. yBottom += cyEdge; vusDatePos = DP_UNDER; } else { if (cxWidth > (cxSquare * 31/10 )) { vmatlfDateTrans.lM31 = -(LONG)53 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)04; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(7,0xe000); vmatlfDateScale.fxM22 = MAKEFIXED(7,0xe000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTMIDDLE; } else { if (cxWidth > (cxSquare * 2)) { /*Goes on the left*/ vmatlfDateTrans.lM31 = -(LONG)52 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)2; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(3,0xd000); vmatlfDateScale.fxM22 = MAKEFIXED(3,0xd000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTDOWN ; } else { /*Goes inside*/ vmatlfDateTrans.lM31 = (LONG)24 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)23; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0); vmatlfDateScale.fxM22 = MAKEFIXED(2,0); vclrDate[SURFACE] = vclrFace[SHADE] ; vclrDate[LIGHT] = vclrFace[LIGHT] ; vclrDate[SHADE] = vclrFace[SHADE]; vclrDate[BACKGROUND] = vclrFace[SURFACE]; vusDatePos = DP_INSIDE; } } } } f = GpiSetPageViewport (hps, &rclPage); f = GpiSetPageViewport (hpsBuffer, &rclPage); /* * Are we iconic? */ f = WinQueryWindowPos (hwndFrame, &swp); fIconic = (BOOL)(swp.fl & SWP_MINIMIZE ); fShowSecondHand = (BOOL) !(fIconic); GpiQueryCharBox(hpsBuffer, &sizef); GpiSetCharBox(hpsBuffer, &sizef); fBufferDirty = TRUE; }
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; }
MRESULT EXPENTRY EDImgWinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { // alla creazione estrae dal testo del controllo il nome della libreria // e l'ID della risorsa da cui ricavare l'immagine switch (msg) { case WM_CREATE: { LHANDLE himg; // handle immagine PSZ psz; // per ricavare nome modulo e id risorsa ULONG idres; // id risorsa HLIB hlib; HAB hab; SIZEL szl; hab = WinQueryAnchorBlock(hwnd); // cerca primo tab lo cambia in 0 e carica lib if (!(psz = memchr((PVOID)((PCREATESTRUCT)mp2)->pszText, '\t', 9))) goto error0; *psz = 0; if (!(hlib = WinLoadLibrary(hab, ((PCREATESTRUCT)mp2)->pszText))) goto error0; // ottiene handle e dimensione immagine if (!(idres = strtoul(++psz, NULL, 10))) goto error1; if (((PCREATESTRUCT)mp2)->flStyle & (ESI_PTR | ESI_ICON | ESI_MINI)) { if (!(himg = WinLoadPointer(HWND_DESKTOP, hlib, idres))) goto error1; if (((PCREATESTRUCT)mp2)->flStyle & ESI_PTR) { // pointer szl.cx = WgetSysValue(SV_CXPOINTER); szl.cy = WgetSysValue(SV_CYPOINTER); } else if (((PCREATESTRUCT)mp2)->flStyle & ESI_ICON) { // icona szl.cx = WgetSysValue(SV_CXICON); szl.cy = WgetSysValue(SV_CYICON); } else { // minicona szl.cx = WgetSysValue(SV_CXICON) / 2; szl.cy = WgetSysValue(SV_CYICON) / 2; } // end if } else { // bitmap if (!(himg = WloadBitmap(hwnd, hlib, idres))) goto error1; if (!WqueryBitmapSize(himg, &szl)) goto error2; } // end if WinDeleteLibrary(hab, hlib); // memorizza handle immagine WinSetWindowULong(hwnd, cbWCstc, (ULONG)himg); *((PCREATESTRUCT)mp2)->pszText = 0; //break; WinSetWindowPos(hwnd, 0, 0, 0, szl.cx, szl.cy, SWP_SIZE|SWP_NOADJUST); break; error2: GpiDeleteBitmap(himg); error1: WinDeleteLibrary(hab, hlib); error0: return (MRESULT)TRUE; } // end case WM_CREATE case WM_ADJUSTWINDOWPOS: // default window processing return WinDefWindowProc(hwnd, msg, mp1, mp2); case WM_PAINT: { LHANDLE himg = (LHANDLE)WinQueryWindowULong(hwnd, cbWCstc); ULONG flStyle = WinQueryWindowULong(hwnd, QWL_STYLE); HPS hps; hps = WinBeginPaint(hwnd, NULLHANDLE, NULL); if (flStyle & (ESI_PTR | ESI_ICON | ESI_MINI)) { WinDrawPointer(hps, 0, 0, himg, (flStyle & ESI_MINI? DP_MINI: DP_NORMAL)); } else { POINTL ptl = {0,0}; WinDrawBitmap(hps, himg, NULL, &ptl, 0, 0, DBM_NORMAL); } // end if WinEndPaint(hps); return (MRESULT)FALSE; } // end case WM_PAINT // restituisce handle immagine corrente case SM_QUERYHANDLE: return (MPARAM)WinQueryWindowULong(hwnd, cbWCstc); // memorizza nuovo handle immagine, forza repaint e restituisce // handle precedente immagine case SM_SETHANDLE: { LHANDLE himg = (LHANDLE)WinQueryWindowULong(hwnd, cbWCstc); if (!WinSetWindowULong(hwnd, cbWCstc, (ULONG)mp1)) return NULLHANDLE; WinRefreshWin(hwnd); return (MRESULT)himg; } // end case SM_SETHANDLE case WM_MATCHMNEMONIC: return (MRESULT)FALSE; case WM_DESTROY: { LHANDLE himg = (LHANDLE)WinQueryWindowULong(hwnd, cbWCstc); if (WinQueryWindowULong(hwnd, QWL_STYLE) & (ESI_PTR | ESI_ICON | ESI_MINI)) { WinDestroyPointer(himg); } else { GpiDeleteBitmap(himg); } // end if } break; } /* endswitch */ return pfnwpWCstc(hwnd, msg, mp1, mp2); // default static controls processing }
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 ); }
/************************************************************************* * * 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 */
/****************************************************************\ * Name: ClkSize() * * Purpose:When the window has been sized, we calculate a page * rectangle which: (a) fills the window rectangle in either * the x or y dimension, (b) appears square, and (c) is centered * in the window rectangle \****************************************************************/ VOID ClkSize (HWND hwnd) { RECTL rclWindow; SIZEF sizef; LONG cxSquare, cySquare, cxEdge, cyEdge; LONG cyHeight; LONG cxWidth; HBITMAP hbm; BITMAPINFOHEADER bmp; /* * First get rid of any buffer bitmap already there. */ hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE); if (hbm != NULLHANDLE) GpiDeleteBitmap (hbm); /* * Get the width and height of the window rectangle. */ WinQueryWindowRect (hwnd, &rclWindow); cxWidth = rclWindow.xRight - rclWindow.xLeft - 2; cyHeight = rclWindow.yTop - rclWindow.yBottom - 2; /* * Now create a bitmap the size of the window. */ bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitcount; hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp, 0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL); GpiSetBitmap (hpsBuffer, hbm); /* * Assume the size of the page rectangle is constrained in the y * dimension,compute the x size which would make the rectangle appear * square, then check the assumption and do the reverse calculation * if necessary. */ cySquare = cyHeight - 2; cxSquare = ( cyHeight * cxRes ) / cyRes; if (cxWidth < cxSquare) { cxSquare = cxWidth - 2; cySquare = (cxWidth * cyRes) / cxRes; } /* * Fill in the page rectangle and set the page viewport. */ RECTL rclPage; // clkdata.c war global!! aber warum? cxEdge = (cxWidth - cxSquare ) / 2; cyEdge = (cyHeight - cySquare ) / 2; rclPage.xLeft = cxEdge; rclPage.xRight = cxWidth - cxEdge; rclPage.yBottom = cyEdge; rclPage.yTop = cyHeight - cyEdge; f = GpiSetPageViewport (hps, &rclPage); f = GpiSetPageViewport (hpsBuffer, &rclPage); fBufferDirty = TRUE; }