BOOL freeBitmapResources(VOID) { HPS hps; if (NULLHANDLE != (hps = WinGetScreenPS(HWND_DESKTOP))) { if (o.tb.on) { _stlrFreeGlobalBitmap(hps, o.tb.a.hbmp, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.i.hbmp, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.sysmenu, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.close, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.hide, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.min, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.rest, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.max, g.timerThrd.hab); } /* endif */ if (o.tb.htbar) { _stlrFreeGlobalBitmap(hps, o.tb.bmp.htbar, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.unhtbar, g.timerThrd.hab); } /* endif */ if (o.tb.roll) { _stlrFreeGlobalBitmap(hps, o.tb.bmp.roll, g.timerThrd.hab); _stlrFreeGlobalBitmap(hps, o.tb.bmp.unroll, g.timerThrd.hab); } /* endif */ WinReleasePS(hps); return TRUE; } /* endif */ return FALSE; }
void wxConvertVectorFontSize( FIXED fxPointSize , PFATTRS pFattrs ) { HPS hPS; HDC hDC; LONG lXFontResolution; LONG lYFontResolution; SIZEF vSizef; hPS = WinGetScreenPS(HWND_DESKTOP); // Screen presentation space // // Query device context for the screen and then query // the resolution of the device for the device context. // hDC = GpiQueryDevice(hPS); DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lXFontResolution); DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lYFontResolution); // // Calculate the size of the character box, based on the // point size selected and the resolution of the device. // The size parameters are of type FIXED, NOT int. // NOTE: 1 point == 1/72 of an inch. // // multiply first to avoid getting vSizef.cx,cy = 0 since fxPointSize // is normally < 72 and FontResolution is typically ca. 100 vSizef.cx = (FIXED)( (fxPointSize * lXFontResolution) / 72 ); vSizef.cy = (FIXED)( (fxPointSize * lYFontResolution) / 72 ); if (pFattrs) { pFattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( vSizef.cy ), 0 ); pFattrs->lAveCharWidth = MAKELONG( HIUSHORT( vSizef.cx ), 0 ); } WinReleasePS(hPS); } // end of wxConvertVectorPointSize
/************************************************************************** * * Name : MyWindowProc * * Description: The window procedure associated with the client area in * the standard frame window. It processes all messages * either sent or posted to the client area, depending on * the message command and parameters. * * Concepts : * * API's : WinLoadString * WinInvalidateRegion * WinPostMsg * WinDefWindowProc * WinBeginPaint * GpiSetColor * GpiSetBackColor * GpiSetBackMix * GpiCharStringAt * WinEndPaint * * Parameters : hwnd = window handle * msg = message code * mp1 = first message parameter * mp2 = second message parameter * * Return : depends on message sent * *************************************************************************/ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { switch( msg ) { case WM_TIMER: { WinInvalidateRegion( hwnd, 0L, FALSE ); break; } case WM_CREATE: /* * Window initialization is performed here in WM_CREATE processing * WinLoadString loads strings from the resource file. */ WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello ); WinLoadString( hab, (HMODULE)0L, IDS_1, STRINGLENGTH, sz1 ); WinLoadString( hab, (HMODULE)0L, IDS_2, STRINGLENGTH, sz2 ); WinLoadString( hab, (HMODULE)0L, IDS_3, STRINGLENGTH, sz3 ); strcpy( szString, szHello ); /* Copy text Hello into szString*/ break; case WM_COMMAND: /* * When the user chooses option 1, 2, or 3 from the Options pull- * down, the text string is set to 1, 2, or 3, and * WinInvalidateRegion sends a WM_PAINT message. * When Exit is chosen, the application posts itself a WM_CLOSE * message. */ { USHORT command; /* WM_COMMAND command value */ command = SHORT1FROMMP(mp1); /* Extract the command value */ switch (command) { case ID_EXITPROG: WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 ); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } break; } case WM_ERASEBACKGROUND: /* * Return TRUE to request PM to paint the window background * in SYSCLR_WINDOW. */ return (MRESULT)( TRUE ); case WM_PAINT: /* * Window contents are drawn here in WM_PAINT processing. */ { HPS hps; /* Presentation Space handle */ RECTL rc; /* Rectangle coordinates */ POINTL pt; /* String screen coordinates */ POINTL pPos; LONG lColor,r,g,b; FATTRS fat; HPS shps = WinGetScreenPS(HWND_DESKTOP); fat.usRecordLength = sizeof(FATTRS); /* sets size of structure */ fat.fsSelection = 0; /* uses default selection */ fat.lMatch = 0L; /* does not force match */ fat.idRegistry = 0; /* uses default registry */ fat.usCodePage = 0; /* code-page 850 */ fat.lMaxBaselineExt = 14L; /* requested font height is 12 pels */ fat.lAveCharWidth = 14L; /* requested font width is 12 pels */ fat.fsType = 0; /* uses default type */ fat.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */ strcpy(fat.szFacename ,"Courier"); WinQueryPointerPos(HWND_DESKTOP, &pPos); hps = WinBeginPaint( hwnd, 0L, &rc ); GpiCreateLogColorTable(shps, 0, LCOLF_RGB, 0, 0, NULL); GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); pt.x = 10; pt.y = 27; /* Set the text coordinates, */ lColor=GpiQueryPel(shps, &pPos); GpiSetBackColor( hps, 16777215); /* its background and */ WinFillRect( hps, &rc, lColor); GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */ b = lColor & 0x000000FF; lColor = lColor >> 8; g = lColor & 0x000000FF; lColor = lColor >> 8; r = lColor & 0x000000FF; WinReleasePS(shps); sprintf(szString,"Color: #%.2X%.2X%.2X",r,g,b); GpiCreateLogFont(hps, NULL, 1L, &fat); GpiSetCharSet(hps, 1L); GpiSetCharMode(hps, CM_MODE1); GpiCharStringAt( hps,&pt ,(LONG)strlen( szString ), szString ); WinEndPaint( hps ); /* Drawing is complete */ break; } case WM_CLOSE: WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/ break; default: /* * Everything else comes here. This call MUST exist * in your window procedure. */ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return (MRESULT)FALSE; } /* End of MyWindowProc */
// ******************************************************************************* // 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; }
/* * Query the font used for various CSS properties (aID) from the system. * For OS/2, only very few fonts are defined in the system, so most of the IDs * resolve to the same system font. * The font queried will give back a string like * 9.WarpSans Bold * 12.Times New Roman Bold Italic * 10.Times New Roman.Strikeout.Underline * 20.Bitstream Vera Sans Mono Obli * (always restricted to 32 chars, at least before the second dot) * We use the value before the dot as the font size (in pt, and convert it to * px using the screen resolution) and then try to use the rest of the string * to determine the font style from it. */ nsresult nsSystemFontsOS2::GetSystemFont(nsSystemFontID aID, nsString* aFontName, gfxFontStyle *aFontStyle) const { #ifdef DEBUG_thebes printf("nsSystemFontsOS2::GetSystemFont: "); #endif char szFontNameSize[MAXNAMEL]; switch (aID) { case eSystemFont_Icon: QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL); #ifdef DEBUG_thebes printf("IconText "); #endif break; case eSystemFont_Menu: QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL); #ifdef DEBUG_thebes printf("Menus "); #endif break; case eSystemFont_Caption: case eSystemFont_MessageBox: case eSystemFont_SmallCaption: case eSystemFont_StatusBar: case eSystemFont_Tooltips: case eSystemFont_Widget: case eSystemFont_Window: // css3 case eSystemFont_Document: case eSystemFont_Workspace: case eSystemFont_Desktop: case eSystemFont_Info: case eSystemFont_Dialog: case eSystemFont_Button: case eSystemFont_PullDownMenu: case eSystemFont_List: case eSystemFont_Field: QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL); #ifdef DEBUG_thebes printf("WindowText "); #endif break; default: NS_WARNING("None of the listed font types, using WarpSans"); if (!IsDBCS()) { strcpy(szFontNameSize, "9.WarpSans"); } else { strcpy(szFontNameSize, "9.WarpSans Combined"); } } // switch #ifdef DEBUG_thebes printf(" (%s)\n", szFontNameSize); #endif char *szFacename = strchr(szFontNameSize, '.'); if (!szFacename || (*(szFacename++) == '\0')) return NS_ERROR_FAILURE; // local DPI for size will be taken into account below aFontStyle->size = atof(szFontNameSize); // determine DPI resolution of screen device to compare compute // font size in pixels HPS ps = WinGetScreenPS(HWND_DESKTOP); HDC dc = GpiQueryDevice(ps); // effective vertical resolution in DPI LONG vertScreenRes = 120; // assume 120 dpi as default DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes); WinReleasePS(ps); // now scale to make pixels from points (1 pt = 1/72in) aFontStyle->size *= vertScreenRes / 72.0; NS_ConvertUTF8toUTF16 fontFace(szFacename); int pos = 0; // this is a system font in any case aFontStyle->systemFont = true; // bold fonts should have " Bold" in their names, at least we hope that they // do, otherwise it's bad luck NS_NAMED_LITERAL_CSTRING(spcBold, " Bold"); if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) { aFontStyle->weight = FONT_WEIGHT_BOLD; // strip the attribute, now that we have set it in the gfxFontStyle fontFace.Cut(pos, spcBold.Length()); } else { aFontStyle->weight = FONT_WEIGHT_NORMAL; } // FIXME: Set aFontStyle->stretch correctly! aFontStyle->stretch = NS_FONT_STRETCH_NORMAL; // similar hopes for italic and oblique fonts... NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic"); NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique"); NS_NAMED_LITERAL_CSTRING(spcObli, " Obli"); if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) { aFontStyle->style = FONT_STYLE_ITALIC; fontFace.Cut(pos, spcItalic.Length()); } else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) { // oblique fonts are rare on OS/2 and not specially supported by // the GPI system, but at least we are trying... aFontStyle->style = FONT_STYLE_OBLIQUE; fontFace.Cut(pos, spcOblique.Length()); } else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) { // especially oblique often gets cut by the 32 char limit to "Obli", // so search for that, too (anything shorter would be ambiguous) aFontStyle->style = FONT_STYLE_OBLIQUE; // In this case, assume that this is the last property in the line // and cut off everything else, too // This is needed in case it was really Obliq or Obliqu... fontFace.Cut(pos, fontFace.Length()); } else { aFontStyle->style = FONT_STYLE_NORMAL; } // just throw away any modifiers that are separated by dots (which are either // .Strikeout, .Underline, or .Outline, none of which have a corresponding // gfxFont property) if ((pos = fontFace.Find(".", false, 0, -1)) > -1) { fontFace.Cut(pos, fontFace.Length()); } #ifdef DEBUG_thebes printf(" after=%s\n", NS_LossyConvertUTF16toASCII(fontFace).get()); printf(" style: %s %s %s\n", (aFontStyle->weight == FONT_WEIGHT_BOLD) ? "BOLD" : "", (aFontStyle->style == FONT_STYLE_ITALIC) ? "ITALIC" : "", (aFontStyle->style == FONT_STYLE_OBLIQUE) ? "OBLIQUE" : ""); #endif NS_NAMED_LITERAL_STRING(quote, "\""); // seems like we need quotes around the font name *aFontName = quote + fontFace + quote; return NS_OK; }
VOID initResources(HINI hini, BOOL bLoadStrings) { HMODULE hmod; CHAR buf[CCHMAXPATH]; ULONG ul; PBYTE p; BOOL rc = FALSE; HPS hps; // /*-*/ dbgPrintf2("--- initResources(%d)\n", bLoadStrings); // get the path of the resource DLL if (0 == (ul = PrfQueryProfileString(HINI_USER, OS2INIAPPL, "path", NULL, buf, sizeof(buf)))) goto exit0; strcpy(buf + ul - 1, SZ_RESMODNAME); // load the resource DLL if (DosLoadModule(NULL, 0, buf, &hmod)) goto exit0; // /*-*/ dbgPrintf2("--- initResources() res module handle: %08x\n", hmod); // get the resource strings if (bLoadStrings) { _stlrLoadStr(hmod, ISSMN_SYSMNTBHIDE, g.text.tbhide); _stlrLoadStr(hmod, ISSMN_SYSMNRLUNRL, g.text.winroll); _stlrLoadStr(hmod, ISSMN_SYSMNALT, g.text.alt); _stlrLoadStr(hmod, ISSMN_SYSMNCTL, g.text.ctrl); _stlrLoadStr(hmod, ISSMN_SYSMNSHFT, g.text.shift); _stlrLoadStr(hmod, ISSMN_SYSMNINS, g.text.ins); _stlrLoadStr(hmod, ISSMN_SYSMNBKSPC, g.text.backspace); _stlrLoadStr(hmod, ISSMN_SYSMNDEL, g.text.del); // /*-*/ dbgPrintf6(">>> %s %s %s %s %s\n", // g.text.tbhide, g.text.winroll, // g.text.alt, g.text.ctrl, g.text.shift); } /* endif */ if (NULLHANDLE == (hps = WinGetScreenPS(HWND_DESKTOP))) goto exit1; if (DosAllocMem((PPVOID)&p, 0x10000, PAG_READ | PAG_WRITE | PAG_COMMIT)) goto exit2; // get the image handles // the image index depends on the titlebar height ul = g.sys.cyTbar > 18; if (!o.gen.disabled) { // if titlebar options are active if (o.tb.on) { // active titlebar ----------------------------------------- // if (o.tb.a.bkgnd == TBARBKGNDBMP) { o.tb.a.hbmp = stlrHBmp(hini, SZPRO_BMPATBARDATA, p, hps, &o.tb.a.size, hmod, IDBMP_TBA); } else if (o.tb.a.bkgnd == TBARBKGNDSHADE) { o.tb.a.hbmp = stlrShadeHBmp(hps, (PSHDCREATE)p, &o.tb.a); GpiSetBitmapOwner(hps, o.tb.a.hbmp, 0); // make global } /* endif */ // inactive titlebar --------------------------------------- if (o.tb.i.bkgnd == TBARBKGNDBMP) { o.tb.i.hbmp = stlrHBmp(hini, SZPRO_BMPITBARDATA, p, hps, &o.tb.i.size, hmod, IDBMP_TBI); } else if (o.tb.i.bkgnd == TBARBKGNDSHADE) { o.tb.i.hbmp = stlrShadeHBmp(hps, (PSHDCREATE)p, &o.tb.i); GpiSetBitmapOwner(hps, o.tb.i.hbmp, 0); // make global } /* endif */ // system menu --------------------------------------------- o.tb.bmp.sysmenu = stlrHBmp(hini, SZPRO_BMPSMENUDATA, p, hps, NULL, hmod, 0); // close window button ------------------------------------- #ifdef STLR_WARP3 o.tb.bmp.close = stlrHBmp(hini, SZPRO_BMPCLOSEDATA, p, hps, NULL, hmod, IDBMP_CLOSE18 + ul); #else o.tb.bmp.close = stlrHBmp(hini, SZPRO_BMPCLOSEDATA, p, hps, NULL, hmod, 0); #endif // hide window button -------------------------------------- o.tb.bmp.hide = stlrHBmp(hini, SZPRO_BMPHIDEDATA, p, hps, NULL, hmod, 0); // minimize window button ---------------------------------- o.tb.bmp.min = stlrHBmp(hini, SZPRO_BMPMINDATA, p, hps, NULL, hmod, 0); // restore window button ----------------------------------- o.tb.bmp.rest = stlrHBmp(hini, SZPRO_BMPRESTDATA, p, hps, NULL, hmod, 0); // maximize window button ---------------------------------- o.tb.bmp.max = stlrHBmp(hini, SZPRO_BMPMAXDATA, p, hps, NULL, hmod, 0); } /* endif */ if (o.tb.htbar) { // hide titlebar button ------------------------------------ o.tb.bmp.htbar = stlrHBmp(hini, SZPRO_BMPHTBARDATA, p, hps, NULL, hmod, IDBMP_HT18 + ul); // unhide titlebar button ---------------------------------- o.tb.bmp.unhtbar = stlrHBmp(hini, SZPRO_BMPUNHTBARDATA, p, hps, NULL, hmod, IDBMP_UHT18 + ul); } /* endif */ if (o.tb.roll) { // roll window button -------------------------------------- o.tb.bmp.roll = stlrHBmp(hini, SZPRO_BMPROLLDATA, p, hps, NULL, hmod, IDBMP_RL18 + ul); // unroll window button ------------------------------------ o.tb.bmp.unroll = stlrHBmp(hini, SZPRO_BMPUNROLLDATA, p, hps, NULL, hmod, IDBMP_URL18 + ul); } /* endif */ } /* endif */ rc = TRUE; DosFreeMem(p); exit2: DosFreeModule(hmod); exit1: WinReleasePS(hps); exit0: if (!rc) stlrlog(IDERR_GETRESMOD); }