static INT CreateMemoryPS (PINST pinstMain, HPS hpsTarget, PRECTL prclTargetWnd) { SIZEL sizl; HDC hdcTarget = GpiQueryDevice(hpsTarget); pinstMain->hdcMem = DevOpenDC(pinstMain->hab,OD_MEMORY,"*", 0L,NULL,hdcTarget); assert (pinstMain->hdcMem != DEV_ERROR); // // Set the size of the presentation space to be created. // sizl.cx = prclTargetWnd->xRight; sizl.cy = prclTargetWnd->yTop; // // Create the memory presentation space for the bitmap. // pinstMain->hpsMemRadar = GpiCreatePS(pinstMain->hab, pinstMain->hdcMem,&sizl, PU_PELS | GPIA_ASSOC | GPIT_MICRO); assert (pinstMain->hpsMemRadar != GPI_ERROR); return 0; }
/************************************************************************** * * Name : InitClientArea() * * Description: Prepares the client area to accept the images * * Concepts : Called once by the Init() routine * - obtain a window device context * - define the image presentation space * - associate the two * - set foreground/background colours & * background mix for the presentation space * * API's : WinOpenWindowDC * GpiCreatePS * GpiSetColor * GpiSetBackColor * GpiSetBackMix * * Parameters : hwnd = client window handle * * Return : TRUE - client area successfully set up * FALSE - client area setup failed * *************************************************************************/ BOOL InitClientArea(HWND hwnd) { SIZEL sizl; sizl.cx = 0L; /* set size to default for device */ sizl.cy = 0L; /* (full screen) */ vhdc = WinOpenWindowDC(hwnd); if (!vhdc) return FALSE; vhps = GpiCreatePS(vhab, vhdc, &sizl, (ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC ); if (!vhps) return FALSE; GpiSetColor(vhps, vlForeClr); GpiSetBackColor(vhps, vlBackClr); GpiSetBackMix(vhps, BM_OVERPAINT); return TRUE; } /* End of InitClientArea */
//---------------------------------------------------------------------------- // NPP_SetWindow: //---------------------------------------------------------------------------- NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* window) { pprintf( szPPR, "NPP_SetWindow\n\r" ); if ( instance == 0 ) return NPERR_INVALID_INSTANCE_ERROR; PluginInstance* This = (PluginInstance*) instance->pdata; // // *Developers*: Before setting fWindow to point to the // new window, you may wish to compare the new window // info to the previous window (if any) to note window // size changes, etc. // // if window handle changed if ( This->hWnd != (HWND)window->window ) { pprintf( szPPR, "HWND (hmf %x) changed, %x --> %x\n\r", This->hmf, (int)This->hWnd, (int)window->window ); // remember the new window This->fWindow = window; if ( This->hWnd ) { // Remove the subclass for the old client window WinSubclassWindow(This->hWnd, This->lpfnOldWndProc); } // remember the new window handle This->hWnd = (HWND)This->fWindow->window; // subclass the window This->lpfnOldWndProc = WinSubclassWindow(This->hWnd, SubClassFunc); AssociateInstance( This->hWnd, This ); /* paint a background for the drawing */ WinQueryWindowRect( This->hWnd, &This->rclWnd ); // WinFillRect( This->hps, &This->rclWnd, CLR_PALEGRAY ); // destroy old PS and create new PS if ( This->hps ) GpiDestroyPS( This->hps ); HDC hdc = WinQueryWindowDC( This->hWnd ); if ( !hdc ) hdc = WinOpenWindowDC( This->hWnd ); SIZEL siz={ 0, 0 }; HAB hab=WinQueryAnchorBlock( This->hWnd ); This->hps = GpiCreatePS( hab, hdc, &siz, PU_PELS | GPIT_NORMAL | GPIA_ASSOC ); pprintf( szPPR, "GpiCreatePS, hdc=%x, hps=%x\n\r", (int)hdc, (int)This->hps ); if ( !This->hps ) { pprintf( szPPR, "GpiCreatePS failed, Err=%x\n\r", WinGetLastError( hab ) ); } SetTransform( This, This->hps, &This->rclWnd ); } else { // check if window coordinates changed. //It may happens for full-screan RECTL rcl; WinQueryWindowRect( This->hWnd, &rcl ); if ( memcmp( &This->rclWnd, &rcl, sizeof( rcl ) ) ) { pprintf( szPPR, "Rect (hmf %x) changed, ( %d, %d ) - ( %d, %d ) --> ( %d, %d ) - ( %d, %d )\n\r", This->hmf, This->rclWnd.xLeft, This->rclWnd.yBottom, This->rclWnd.xRight, This->rclWnd.yTop, rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop ); memcpy( &This->rclWnd, &rcl, sizeof( rcl ) ); SetTransform( This, This->hps, &This->rclWnd ); } } return NPERR_NO_ERROR; }
QT_BEGIN_NAMESPACE HPS qt_alloc_mem_ps(int w, int h, HPS compat = 0) { HDC hdcCompat = NULLHANDLE; if (compat) hdcCompat = GpiQueryDevice(compat); static PCSZ hdcData[4] = { "Display", NULL, NULL, NULL }; HDC hdc = DevOpenDC(0, OD_MEMORY, "*", 4, (PDEVOPENDATA) hdcData, hdcCompat); if (!hdc) { qWarning( "alloc_mem_dc: DevOpenDC failed with %08lX!", WinGetLastError(0)); return NULLHANDLE; } SIZEL size = { w, h }; HPS hps = GpiCreatePS(0, hdc, &size, PU_PELS | GPIA_ASSOC | GPIT_MICRO); if (hps == NULLHANDLE) { qWarning("alloc_mem_dc: GpiCreatePS failed wit %08lX!", WinGetLastError(0)); return NULLHANDLE; } // @todo later // if (QColor::hPal()) { // GpiSelectPalette(hps, QColor::hPal()); // } else { // direct RGB mode GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); // } return hps; }
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; }
/*@ 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; }
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize, int aPreview) : mWnd(0), mDC(aDC), mPS(0), mSize(aSize), mSurfType(os2Print) { // Create a PS using the same page size as the device. SIZEL sizel = { 0, 0 }; mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIA_ASSOC | (aPreview ? GPIT_MICRO : GPIT_NORMAL)); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!"); printf("gfxOS2Surface for print - DC= %lx PS= %lx w= %d h= %d preview= %d\n", mDC, mPS, mSize.width, mSize.height, aPreview); // Create a cairo surface for the PS associated with the printer DC. // For print preview, create a null surface that can be queried but // generates no output. Otherwise, create a printing surface that // uses GPI functions to render the output. cairo_surface_t* surf; if (aPreview) surf = cairo_os2_surface_create_null_surface(mPS, mSize.width, mSize.height); else surf = cairo_os2_printing_surface_create(mPS, mSize.width, mSize.height); Init(surf); // Cairo allocates temporary buffers when it converts images from // BGR4 to BGR3 but there's no way to determine their size. RecordMemoryUsed(OS2_OVERHEAD); }
/* Initialize data for our drawing thread */ int Draw_Initialize(void) { int i; /* Temporary variables */ /* For each symbol, open a memory devicecontext, create a presentation space and load the bitmap from the EXE file */ for(i=1;i<RB_BORDER;i++) { if(!(hdcRB[i]=DevOpenDC(hab, /* Open device context with anchor block handle of our application */ OD_MEMORY, /* Type of device context (memory) */ (PSZ)"*", /* Device information token (no initialization) */ 8L, /* Number of items (of deviceopendata) */ (PDEVOPENDATA)&dcRB[i], /* Open device context data */ (HDC)NULL))) /* Compatible device context (compatibilty with screen) */ GEN_ERR(hab,hwndFrame,hwndClient); if(!(hpsRB[i]=GpiCreatePS(hab, /* Create a presentation space with our anchor block handle */ hdcRB[i], /* Device context handle (of our symbols) */ &sizelRB, /* Presentation space size (or our symbols) */ GPIA_ASSOC|PU_PELS))) /* Options (assoziate to screen, pels as unit) */ GEN_ERR(hab,hwndFrame,hwndClient); /* Load bitmap from EXE file */ if(!(hbmRB[i]=GpiLoadBitmap(hpsRB[i], (HMODULE)0, /* Ressource (EXE file) */ RB_RESSOURCE_ID[i], /* ID of bitmap within ressource */ 0L, /* Width of bitmap in pels (no streching) */ 0L))) /* Height of bitmap in pels (no streching) */ GEN_ERR(hab,hwndFrame,hwndClient); } return(0); }
void PM_mainloop(VOID *arg) { SIZEL sizelHps = {0,0}; HAB hab; // Anchor Block to PM HMQ hmq; // Handle to Msg Queue HDC hdc; // Handle to Device (Window-Screen) QMSG qmsg; // Msg Queue Event video_canvas_t *ptr=(video_canvas_t*)arg; hab = WinInitialize(0); // Initialize PM hmq = WinCreateMsgQueue(hab, 0); // Create Msg Queue // 2048 Byte Memory (Used eg for the Anchor Blocks WinRegisterClass(hab, szClientClass, PM_winProc, CS_SIZEREDRAW, 2048); (*ptr)->hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_ANIMATE, &flFrameFlags, szClientClass, szTitleBarText, 0L, 0, 0, &((*ptr)->hwndClient)); WinSetWindowPos((*ptr)->hwndFrame, HWND_TOP, 0, 0, (*ptr)->width*stretch, (*ptr)->height*stretch+ WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR), // +1 with gcc? SWP_SIZE|SWP_SHOW|SWP_ZORDER|SWP_ACTIVATE); // Make visible, resize, top window WinSetWindowPtr((*ptr)->hwndClient, QWL_USER, (VOID*)(*ptr)); // -------------------- // maybe ---> WM_CREATE // -------------------- hdc = WinOpenWindowDC((*ptr)->hwndFrame); (*ptr)->hps = GpiCreatePS(WinQueryAnchorBlock((*ptr)->hwndFrame), hdc, &sizelHps, PU_PELS|GPIF_DEFAULT|GPIT_MICRO|GPIA_ASSOC); // GPIT_NORMAL does also work with vac++ (*ptr)->pbmi = lib_calloc(1, 16+sizeof(RGB2)*256); (*ptr)->pbmi->cbFix = 16; // Size of cbFix, cPlanes, cBitCount = Begin of RGB2 (*ptr)->pbmi->cPlanes = 1; (*ptr)->pbmi->cBitCount = 8; // Using 8-bit color mode (*ptr)->palette=(RGB2*)((ULONG)(*ptr)->pbmi+(*ptr)->pbmi->cbFix); vidlog("pbmiAllocated",0); (*ptr)->pbmi_initialized = TRUE; // All stuff for pbmi created // DosReleaseMutexSem(hmtx); // gfx init end //----------------------- while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0)) WinDispatchMsg (hab, &qmsg) ; // (*ptr)->pbmi_initialized = FALSE; DosRequestMutexSem(hmtx, SEM_INDEFINITE_WAIT); GpiDestroyPS((*ptr)->hps); WinDestroyWindow ((*ptr)->hwndFrame); // why was this commented out? --> WM_CLOSE ?? WinDestroyMsgQueue(hmq); // Destroy Msg Queue WinTerminate (hab); // Release Anchor to PM lib_free((*ptr)->pbmi); // is this the right moment to do this??? // lib_free(*ptr); // Vice crashes... why??? This must be done in the main thread! exit(0); // Kill VICE, All went OK }
/****************************************************************\ * *-------------------------------------------------------------- * Name:ClkCreate() * * Purpose:Intialize a newly created client window * * Returns: * 1 - if sucessful execution completed * 0 - if error \****************************************************************/ VOID ClkCreate ( HWND hwnd ) { LONG cxScreen , cyScreen; /* screen dimensions */ LONG xLeft , yBottom ; /* frame window location */ ULONG cbBuf; LONG cyHeight; LONG cxWidth; // hwndClient = hwnd; // extern SIZEL sizl; clkdata.h // SIZEL sizl = { 200 , 200 }; clkdata.c /* determine screen dimensions */ /* open a device context and create a presentation space */ hdc = WinOpenWindowDC (hwnd); hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); /* * Create our off-screen 'buffer'. */ hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc); hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL); // ULONG cxRes , cyRes; clkdata.c // ULONG cColorPlanes, cColorBitcount; clkdata.c /* get the device resolutions so we can make the face appear circular */ DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes); DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes); DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes); DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount); }
/*@ XBitmap :: XBitmap(const XPoint * pp1, const LONG m) @group constructors/destructors @remarks Construct a bitmap @parameters <t 'ø' c=2> øXPoint * p øleft-lower corner øLONG mode ømode, default is ROP_SRCCOPY </t> @exceptions If the method fails an exception of the type XException is thrown. */ XBitmap :: XBitmap(const XPoint * pp1, const LONG m):XGraphicObject(pp1) { mode = m; owner = NULL; hdc = DevOpenDC(XApplication::GetApplication()->GetAnchorBlock(), OD_MEMORY, (PSZ) "*", 0, (PDEVOPENDATA) NULL, 0L); if (hdc == 0) OOLThrow("error creating device context", 4); hps = GpiCreatePS(XApplication::GetApplication()->GetAnchorBlock(), hdc, &g, PU_PELS | GPIA_ASSOC); if (hps == 0) OOLThrow("error creating presentation space", 5); width = height = cx = cy = 0; }
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize, gfxImageFormat aImageFormat) : mWnd(0), mSize(aSize) { #ifdef DEBUG_thebes_2 printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this, aSize.width, aSize.height, aImageFormat); #endif // in this case we don't have a window, so we create a memory presentation // space to construct the cairo surface on // create a PS, partly taken from nsOffscreenSurface::Init(), i.e. nsDrawingSurfaceOS2.cpp DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 }; SIZEL sizel = { 0, 0 }; // use same page size as device mDC = DevOpenDC(0, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&dop, NULLHANDLE); NS_ASSERTION(mDC != DEV_ERROR, "Could not create memory DC"); mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on memory DC!"); // now create a bitmap of the right size BITMAPINFOHEADER2 hdr = { 0 }; hdr.cbFix = sizeof(BITMAPINFOHEADER2); hdr.cx = mSize.width; hdr.cy = mSize.height; hdr.cPlanes = 1; // find bit depth LONG lBitCount = 0; DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); hdr.cBitCount = (USHORT)lBitCount; mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap in memory!"); // set final stats & select bitmap into PS GpiSetBitmap(mPS, mBitmap); // now we can finally create the cairo surface on the in-memory PS cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); #ifdef DEBUG_thebes_2 printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); #endif // Normally, OS/2 cairo surfaces have to be forced to redraw completely // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in // full, so that is not necessary here. // manual refresh is done from nsWindow::OnPaint cairo_os2_surface_set_manual_window_refresh(surf, 1); Init(surf); }
// initializes the window PS and the off-screen buffer VOID InitPS( const HWND hwnd ) { SIZEL g = { 0, 0 }; /* we are called before the global hwndFrame is valid */ hwndFrame = WinQueryWindow ( hwnd , QW_PARENT) ; wcprintf("Muell: %x", WinGetLastError( hab ) ); hdcGlob = WinOpenWindowDC( hwnd ); hpsGlob = GpiCreatePS( hab, hdcGlob, &g, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC ); /* * Create our off-screen 'buffer'. */ // hdcGlob als letzten Parameter ist neu: hdcBufferGlob = DevOpenDC( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdcGlob ); hpsBufferGlob = GpiCreatePS( hab, hdcBufferGlob, &g, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC ); /* get the device resolutions */ DevQueryCaps( hdcGlob, CAPS_COLOR_PLANES, 1L, &cColorPlanes ); DevQueryCaps( hdcGlob, CAPS_COLOR_BITCOUNT, 1L, &cColorBitCount ); }
// 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); }
/* SaverWindowProc This is the window procedure of the screen-size window that is created when the saver starts. There should be no reason to alter the code. Note that we do not process WM_PAINT messages. They are forwarded to the default window procedure, which just validates the window area and does no drawing. All drawing to the window should be done in the drawing-thread. Therefore, if you want to blank the screen before drawing on it for instance, issue a WinFillRect call at the beginning of your drawing-thread. */ MRESULT EXPENTRY SaverWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static SIZEL pagesize={0, 0}; switch(msg){ case WM_CREATE: // reset the "stop" flag stop_draw_thread = FALSE; // store window handle hwndSaver = hwnd; // get hdc and create normal presentation space hdc = WinOpenWindowDC (hwnd); hps = GpiCreatePS (hab, hdc, &pagesize, GPIA_ASSOC|PU_PELS|GPIT_NORMAL); // start the drawing-thread tidDraw = _beginthread(draw_thread, NULL, STACKSIZE, NULL); // create thread to control priority of drawing thread if(low_priority){ stop_priority_thread = FALSE; DosCreateThread(&tidPriority, (PFNTHREAD)priority_thread, 0, 2L, 1000); } // create timer that moves the saver window to top regularly WinStartTimer(hab, hwndSaver, IDT_ZORDERTIMER, ZORDERTIMERSTEP); return (MRESULT)FALSE; case WM_TIMER: if(SHORT1FROMMP(mp1) == IDT_ZORDERTIMER){ // move saver window to top WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER); return (MRESULT)0; } break; case WM_DESTROY: // destroy the presentation space GpiDestroyPS(hps); // stop the z-order timer WinStopTimer(hab, hwndSaver, IDT_ZORDERTIMER); break; case WM_PAINT: // just validate the update area. all drawing is done // in the drawing-thread. return WinDefWindowProc(hwnd, msg, mp1, mp2); } return WinDefWindowProc(hwnd, msg, mp1, mp2); }
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize) : mWnd(0), mDC(aDC), mBitmap(nullptr), mSize(aSize) { #ifdef DEBUG_thebes_2 printf("gfxOS2Surface[%#x]::gfxOS2Surface(HDC=%#x, Size=%dx%d)\n", (unsigned int)this, (unsigned int)aDC, aSize.width, aSize.height); #endif SIZEL sizel = { 0, 0 }; // use same page size as device mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!"); // now create a bitmap of the right size BITMAPINFOHEADER2 hdr = { 0 }; hdr.cbFix = sizeof(BITMAPINFOHEADER2); hdr.cx = mSize.width; hdr.cy = mSize.height; hdr.cPlanes = 1; // find bit depth LONG lBitCount = 0; DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); hdr.cBitCount = (USHORT)lBitCount; mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap for printer!"); // set final stats & select bitmap into PS GpiSetBitmap(mPS, mBitmap); // now we can finally create the cairo surface on the in-memory PS cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); #ifdef DEBUG_thebes_2 printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); #endif // Normally, OS/2 cairo surfaces have to be forced to redraw completely // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in // full, so that is not necessary here. Init(surf); }
//---------------------------------------------------------------------------- // 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; }
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; }
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; }
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 ); }
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); } }
// ******************************************************************************* // 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; }
// ******************************************************************************* // 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; } }
/* Message processing for our PM Window class */ MRESULT EXPENTRY Message_Process( HWND handle, ULONG mess, MPARAM parm1, MPARAM parm2 ) { static HDC screen_dc; static HPS screen_ps; static BOOL minimized; SIZEL sizl; SWP swp; grPMSurface* surface; /* get the handle to the window's surface -- note that this */ /* value will be null when the window is created */ surface = (grPMSurface*)WinQueryWindowPtr( handle, QWL_USER ); if (!surface) { surface = the_surface; WinSetWindowPtr( handle, QWL_USER, surface ); } switch( mess ) { case WM_DESTROY: /* warn the main thread to quit if it didn't know */ surface->event.type = gr_event_key; surface->event.key = grKeyEsc; DosPostEventSem( surface->event_lock ); break; case WM_CREATE: /* set original magnification */ minimized = FALSE; /* create Device Context and Presentation Space for screen. */ screen_dc = WinOpenWindowDC( handle ); screen_ps = GpiCreatePS( surface->anchor, screen_dc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC | GPIF_DEFAULT ); /* take the input focus */ WinFocusChange( HWND_DESKTOP, handle, 0L ); LOG(( "screen_dc and screen_ps have been created\n" )); /* To permit F9, F10 and others to pass through to the application */ if (TRUE != WinSetAccelTable (surface->anchor, 0, surface->frame_window)) { printf( "Error - failed to clear accel table\n"); } break; case WM_MINMAXFRAME: /* to update minimized if changed */ swp = *((PSWP) parm1); if ( swp.fl & SWP_MINIMIZE ) minimized = TRUE; if ( swp.fl & SWP_RESTORE ) minimized = FALSE; return WinDefWindowProc( handle, mess, parm1, parm2 ); break; case WM_ERASEBACKGROUND: case WM_PAINT: /* copy the memory image of the screen out to the real screen */ LOCK( surface->image_lock ); WinBeginPaint( handle, screen_ps, NULL ); /* main image and magnified picture */ GpiBitBlt( screen_ps, surface->image_ps, 4L, surface->blit_points, ROP_SRCCOPY, BBO_AND ); WinEndPaint( screen_ps ); UNLOCK( surface->image_lock ); break; case WM_HELP: /* this really is a F1 Keypress !! */ surface->event.key = grKeyF1; goto Do_Key_Event; case WM_CHAR: if ( CHARMSG( &mess )->fs & KC_KEYUP ) break; /* look for a specific vkey */ { int count = sizeof( key_translators )/sizeof( key_translators[0] ); Translator* trans = key_translators; Translator* limit = trans + count; for ( ; trans < limit; trans++ ) if ( CHARMSG(&mess)->vkey == trans->os2key ) { surface->event.key = trans->grkey; goto Do_Key_Event; } } /* otherwise, simply record the character code */ if ( (CHARMSG( &mess )->fs & KC_CHAR) == 0 ) break; surface->event.key = CHARMSG(&mess)->chr; Do_Key_Event: surface->event.type = gr_event_key; DosPostEventSem( surface->event_lock ); break; default: return WinDefWindowProc( handle, mess, parm1, parm2 ); } return (MRESULT) FALSE; }
static grPMSurface* init_surface( grPMSurface* surface, grBitmap* bitmap ) { PBITMAPINFO2 bit; SIZEL sizl = { 0, 0 }; LONG palette[256]; LOG(( "Os2PM: init_surface( %08lx, %08lx )\n", (long)surface, (long)bitmap )); LOG(( " -- input bitmap =\n" )); LOG(( " -- mode = %d\n", bitmap->mode )); LOG(( " -- grays = %d\n", bitmap->grays )); LOG(( " -- width = %d\n", bitmap->width )); LOG(( " -- height = %d\n", bitmap->rows )); /* create the bitmap - under OS/2, we support all modes as PM */ /* handles all conversions automatically.. */ if ( grNewBitmap( bitmap->mode, bitmap->grays, bitmap->width, bitmap->rows, bitmap ) ) return 0; LOG(( " -- output bitmap =\n" )); LOG(( " -- mode = %d\n", bitmap->mode )); LOG(( " -- grays = %d\n", bitmap->grays )); LOG(( " -- width = %d\n", bitmap->width )); LOG(( " -- height = %d\n", bitmap->rows )); bitmap->pitch = -bitmap->pitch; surface->root.bitmap = *bitmap; /* create the image and event lock */ DosCreateEventSem( NULL, &surface->event_lock, 0, TRUE ); DosCreateMutexSem( NULL, &surface->image_lock, 0, FALSE ); /* create the image's presentation space */ surface->image_dc = DevOpenDC( gr_anchor, OD_MEMORY, (PSZ)"*", 0L, 0L, 0L ); surface->image_ps = GpiCreatePS( gr_anchor, surface->image_dc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC | GPIF_DEFAULT ); GpiSetBackMix( surface->image_ps, BM_OVERPAINT ); /* create the image's PM bitmap */ bit = (PBITMAPINFO2)grAlloc( sizeof(BITMAPINFO2) + 256*sizeof(RGB2) ); surface->bitmap_header = bit; bit->cbFix = sizeof( BITMAPINFOHEADER2 ); bit->cx = surface->root.bitmap.width; bit->cy = surface->root.bitmap.rows; bit->cPlanes = 1; bit->argbColor[0].bBlue = 255; bit->argbColor[0].bGreen = 0; bit->argbColor[0].bRed = 0; bit->argbColor[1].bBlue = 0; bit->argbColor[1].bGreen = 255; bit->argbColor[1].bRed = 0; bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 ); if (bitmap->mode == gr_pixel_mode_gray) { RGB2* color = bit->argbColor; int x, count; count = bitmap->grays; for ( x = 0; x < count; x++, color++ ) { color->bBlue = color->bGreen = color->bRed = (((count-x)*255)/count); } } else { RGB2* color = bit->argbColor; color[0].bBlue = color[0].bGreen = color[0].bRed = 0; color[1].bBlue = color[1].bGreen = color[1].bRed = 255; } surface->os2_bitmap = GpiCreateBitmap( surface->image_ps, (PBITMAPINFOHEADER2)bit, 0L, NULL, NULL ); GpiSetBitmap( surface->image_ps, surface->os2_bitmap ); bit->cbFix = sizeof( BITMAPINFOHEADER2 ); GpiQueryBitmapInfoHeader( surface->os2_bitmap, (PBITMAPINFOHEADER2)bit ); surface->bitmap_header = bit; /* for gr_pixel_mode_gray, create a gray-levels logical palette */ if ( bitmap->mode == gr_pixel_mode_gray ) { int x, count; count = bitmap->grays; for ( x = 0; x < count; x++ ) palette[x] = (((count-x)*255)/count) * 0x010101; /* create logical color table */ GpiCreateLogColorTable( surface->image_ps, (ULONG) LCOL_PURECOLOR, (LONG) LCOLF_CONSECRGB, (LONG) 0L, (LONG) count, (PLONG) palette ); /* now, copy the color indexes to surface->shades */ for ( x = 0; x < count; x++ ) surface->shades[x] = GpiQueryColorIndex( surface->image_ps, 0, palette[x] ); } /* set up the blit points array */ surface->blit_points[1].x = surface->root.bitmap.width; surface->blit_points[1].y = surface->root.bitmap.rows; surface->blit_points[3] = surface->blit_points[1]; /* Finally, create the event handling thread for the surface's window */ DosCreateThread( &surface->message_thread, (PFNTHREAD) RunPMWindow, (ULONG) surface, 0UL, 32920 ); /* wait for the window creation */ LOCK(surface->image_lock); UNLOCK(surface->image_lock); surface->root.done = (grDoneSurfaceFunc) done_surface; surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle; surface->root.set_title = (grSetTitleFunc) set_title; surface->root.listen_event = (grListenEventFunc) listen_event; /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */ return surface; }
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; }
/****************************************************************\ * *-------------------------------------------------------------- * * Name:ClkCreate() * * Purpose:Intialize a newly created client window * * * * Usage: * * Method: * - * * - * - * * - * - * * Returns: * 1 - if sucessful execution completed * 0 - if error \****************************************************************/ VOID ClkCreate ( HWND hwnd ) { LONG cxScreen , cyScreen; /* screen dimensions */ LONG xLeft , yBottom ; /* frame window location */ ULONG cbBuf; LONG cyHeight; LONG cxWidth; hwndClient = hwnd; WinLoadString(hab, NULLHANDLE, IDS_TITLE, 0, (PSZ)szTitle ); WinLoadString(hab, NULLHANDLE, IDS_HELPTITLE, 256, (PSZ)szHelpTitle); GetCountryDependent(); /* we are called before the global hwndFrame is valid */ hwndFrame = WinQueryWindow ( hwnd , QW_PARENT) ; hwndTitleBar = WinWindowFromID ( hwndFrame , FID_TITLEBAR ) ; hwndSysMenu = WinWindowFromID ( hwndFrame , FID_SYSMENU ) ; hwndMinMax = WinWindowFromID ( hwndFrame , FID_MINMAX ) ; /* load our menus */ hwndMenu = WinLoadMenu (hwndFrame, NULLHANDLE, IDR_MAIN); /* determine screen dimensions */ /* open a device context and create a presentation space */ hdc = WinOpenWindowDC (hwnd); hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); /* * Create our off-screen 'buffer'. */ hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc); hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL); /* get the device resolutions so we can make the face appear circular */ DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes); DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes); DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes); DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount); cxScreen = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN); cyScreen = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN); /* * Calculate an initial window position and size. */ xLeft = cxScreen / 8; yBottom = cyScreen / 2; cxWidth = cxScreen / 3; cyHeight = cyScreen / 2; WinSetWindowPos (hwndFrame, NULLHANDLE, xLeft, yBottom, cxWidth, cyHeight, SWP_SIZE | SWP_MOVE | SWP_ACTIVATE); cbBuf = sizeof(cp); if (!PrfQueryProfileData(HINI_USER, SZ_APPNAME, SZ_KEYNAME, &cp, &cbBuf)) { cp.usMajorTickPref = CLKTM_ALWAYS; cp.usMinorTickPref = CLKTM_NOTICONIC; cp.clrBackground = 0x00008080; cp.clrFace = 0x00008080; cp.clrHourHand = RGB_RED; cp.clrMinuteHand = RGB_RED; cp.fControlsHidden = FALSE; cp.usDispMode = DM_TIME | DM_ANALOG | DM_SECONDHAND; cp.alarm.uchHour = 0; cp.alarm.uchMinutes = 0; cp.alarm.usMode = 0; SetRGBColors(); /* position the window and make it visible */ WinSetWindowPos( hwndFrame , NULLHANDLE , xLeft , yBottom , cxWidth , cyHeight , SWP_SIZE | SWP_MOVE | SWP_ACTIVATE); WinQueryWindowPos(hwndFrame, &cp.swp); } else { /*Protect against garbage swp*/ cp.swp.hwnd = hwndFrame; cp.swp.hwndInsertBehind = HWND_TOP; cp.swp.fl = (cp.swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE)) | SWP_SIZE | SWP_MOVE | SWP_ACTIVATE; SetRGBColors(); WinSetMultWindowPos(hab, &cp.swp, 1); } if (cp.fControlsHidden) ClkHideFrameControls (hwndFrame); /* * Check relevant items. */ WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TIME, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_TIME)? MIA_CHECKED : ~MIA_CHECKED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_DATE, TRUE), MPFROM2SHORT( MIA_DISABLED, ( (!(cp.usDispMode & DM_TIME))? MIA_DISABLED : ~MIA_DISABLED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_DATE, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_DATE)? MIA_CHECKED : ~MIA_CHECKED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TIME, TRUE), MPFROM2SHORT( MIA_DISABLED, ( ((!(cp.usDispMode & DM_DATE) || (cp.usDispMode & DM_ANALOG)))? MIA_DISABLED : ~MIA_DISABLED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( (cp.usDispMode & DM_DIGITAL) ?IDM_DIGITAL :IDM_ANALOG, TRUE), MPFROM2SHORT( MIA_CHECKED, MIA_CHECKED)); WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_SECONDHAND, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_SECONDHAND) ? MIA_CHECKED : ~MIA_CHECKED))); /* * Disable these items if the digital clock is visible * since they won't apply. */ if (cp.usDispMode & DM_DIGITAL) { WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_SECONDHAND, TRUE), MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)); WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TICKS, TRUE), MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED)); } /* have we been asked to start as an icon? */ if (fStartAsIcon) WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 0, 0, SWP_MINIMIZE); WinShowWindow(hwndFrame, TRUE); /* get the time in a format for dislaying */ DosGetDateTime(&dt); dt.hours = (UCHAR )(dt.hours * (UCHAR) 5) % (UCHAR) 60 + dt.minutes / (UCHAR)12; /* start a timer */ WinStartTimer (hab, hwnd, IDR_MAIN, 1000); WinLoadString(hab, NULLHANDLE, IDS_TITLE, 80, (PSZ)szTitle); GetCountryDependent(); }
// ------------------------------------------------------------------------------------------------------------ MRESULT EXPENTRY ClientWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { BOOL fOK; RECTL rectl; SIZEL sizel; HPS hps; switch( msg ) { case WM_CLOSE: globals.fCloseMsgSent = TRUE; WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 ); WinPostMsg( globals.hwndObject, WM_QUIT, 0, 0 ); return 0; case WM_COMMAND: switch( SHORT1FROMMP( mp1 )) { case ID_RUN: WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 ); WinInvalidateRect( hwnd, NULL, FALSE ); WinPostMsg( globals.hwndObject, WM_USER_START_REXX, (MPARAM)hwnd, 0 ); break; } return 0; case WM_CREATE: // disable client window until application initializes WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 ); globals.hwndFrame = WinQueryWindow( hwnd, QW_PARENT ); globals.hwndTitlebar = WinWindowFromID( globals.hwndFrame, FID_TITLEBAR ); globals.hwndMenubar = WinWindowFromID( globals.hwndFrame, FID_MENU ); // create title bar text; set into title bar sprintf( globals.szCaption, "%s - %s", CAPTION, globals.szRexxFileName ); WinSetWindowText( globals.hwndTitlebar, globals.szCaption ); // get window DC globals.hdcScreen = WinOpenWindowDC( hwnd ); assert( globals.hdcScreen ); // create a normal PS for the screen; coordinate system is 1/100 inch per unit of measure sizel.cx = sizel.cy = 0; globals.hpsScreen = GpiCreatePS( globals.hab, globals.hdcScreen, &sizel, PU_LOENGLISH | GPIF_LONG | GPIT_NORMAL | GPIA_ASSOC ); assert( globals.hpsScreen ); // object window operates on thread 2 globals.tidObject = _beginthread( threadmain, NULL, LEN_STACK, NULL ); assert( globals.tidObject ); return 0; case WM_MOUSEMOVE: WinSetPointer( HWND_DESKTOP, WinQuerySysPointer( HWND_DESKTOP, globals.fBusy ? SPTR_WAIT:SPTR_ARROW, FALSE )); return (MRESULT)1; case WM_PAINT: hps = WinBeginPaint( hwnd, globals.hpsScreen, &rectl ); fOK = WinFillRect( hps, &rectl, SYSCLR_WINDOW ); assert( fOK ); if( !globals.fBusy ) { // playback the retained GPI drawing orders GpiDrawChain( globals.hpsScreen ); } WinEndPaint( hps ); return 0; case WM_USER_ACK: // object window has posted ack; re-enable the window WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, 0, 0 ); return 0; case WM_USER_DISABLE_CLIENT: globals.fBusy = TRUE; WinEnableWindow( globals.hwndClient, FALSE ); WinEnableMenuItem( globals.hwndMenubar, ID_RUN, FALSE ); return 0; case WM_USER_ENABLE_CLIENT: globals.fBusy = FALSE; WinEnableWindow( globals.hwndClient, TRUE ); WinEnableMenuItem( globals.hwndMenubar, ID_RUN, TRUE ); return 0; } return WinDefWindowProc( hwnd, msg, mp1, mp2 ); }
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 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 }