Changeset 126
- Timestamp:
- Dec 22, 2001, 12:10:30 PM (24 years ago)
- Location:
- trunk/src/helpers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r123 r126 334 334 335 335 *pcbAllocated = c * cbArrayItem; 336 if (!(*ppv = malloc(*pcbAllocated)))336 if (!(*ppv = (PBYTE)malloc(*pcbAllocated))) 337 337 return ERROR_NOT_ENOUGH_MEMORY; 338 338 … … 1779 1779 * 1780 1780 *@@added V0.9.16 (2001-10-19) [umoeller] 1781 *@@changed V0.9.16 (2001-12-18) [umoeller]: fixed error codes 1781 1782 */ 1782 1783 … … 1789 1790 APIRET arc = NO_ERROR; 1790 1791 1791 // run this first, because if the file doesn't 1792 // exists, DosOpen only returns ERROR_OPEN_FAILED, 1793 // which isn't that meaningful 1794 // V0.9.16 (2001-12-08) [umoeller] 1795 if (!(arc = doshQueryPathSize(pcszFilename, 1796 pcbFile))) 1797 { 1798 ULONG fsOpenFlags = 0, 1799 fsOpenMode = OPEN_FLAGS_FAIL_ON_ERROR 1800 | OPEN_FLAGS_NO_LOCALITY 1801 | OPEN_FLAGS_NOINHERIT; 1802 1803 switch (flOpenMode & XOPEN_ACCESS_MASK) 1792 ULONG fsOpenFlags = 0, 1793 fsOpenMode = OPEN_FLAGS_FAIL_ON_ERROR 1794 | OPEN_FLAGS_NO_LOCALITY 1795 | OPEN_FLAGS_NOINHERIT; 1796 1797 switch (flOpenMode & XOPEN_ACCESS_MASK) 1798 { 1799 case XOPEN_READ_EXISTING: 1800 fsOpenFlags = OPEN_ACTION_FAIL_IF_NEW 1801 | OPEN_ACTION_OPEN_IF_EXISTS; 1802 fsOpenMode |= OPEN_SHARE_DENYWRITE 1803 | OPEN_ACCESS_READONLY; 1804 // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING")); 1805 1806 // run this first, because if the file doesn't 1807 // exists, DosOpen only returns ERROR_OPEN_FAILED, 1808 // which isn't that meaningful 1809 // V0.9.16 (2001-12-08) [umoeller] 1810 arc = doshQueryPathSize(pcszFilename, 1811 pcbFile); 1812 break; 1813 1814 case XOPEN_READWRITE_APPEND: 1815 fsOpenFlags = OPEN_ACTION_CREATE_IF_NEW 1816 | OPEN_ACTION_OPEN_IF_EXISTS; 1817 fsOpenMode |= OPEN_SHARE_DENYREADWRITE 1818 | OPEN_ACCESS_READWRITE; 1819 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_APPEND")); 1820 break; 1821 1822 case XOPEN_READWRITE_NEW: 1823 fsOpenFlags = OPEN_ACTION_CREATE_IF_NEW 1824 | OPEN_ACTION_REPLACE_IF_EXISTS; 1825 fsOpenMode |= OPEN_SHARE_DENYREADWRITE 1826 | OPEN_ACCESS_READWRITE; 1827 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_NEW")); 1828 break; 1829 } 1830 1831 if ((!arc) && fsOpenFlags && pcbFile && ppFile) 1832 { 1833 PXFILE pFile; 1834 if (pFile = NEW(XFILE)) 1804 1835 { 1805 case XOPEN_READ_EXISTING: 1806 fsOpenFlags = OPEN_ACTION_FAIL_IF_NEW 1807 | OPEN_ACTION_OPEN_IF_EXISTS; 1808 fsOpenMode |= OPEN_SHARE_DENYWRITE 1809 | OPEN_ACCESS_READONLY; 1810 // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING")); 1811 break; 1812 1813 case XOPEN_READWRITE_APPEND: 1814 fsOpenFlags = OPEN_ACTION_CREATE_IF_NEW 1815 | OPEN_ACTION_OPEN_IF_EXISTS; 1816 fsOpenMode |= OPEN_SHARE_DENYREADWRITE 1817 | OPEN_ACCESS_READWRITE; 1818 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_APPEND")); 1819 break; 1820 1821 case XOPEN_READWRITE_NEW: 1822 fsOpenFlags = OPEN_ACTION_CREATE_IF_NEW 1823 | OPEN_ACTION_REPLACE_IF_EXISTS; 1824 fsOpenMode |= OPEN_SHARE_DENYREADWRITE 1825 | OPEN_ACCESS_READWRITE; 1826 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_NEW")); 1827 break; 1828 } 1829 1830 if ((!arc) && fsOpenFlags && pcbFile && ppFile) 1831 { 1832 PXFILE pFile; 1833 if (pFile = NEW(XFILE)) 1836 ULONG ulAction; 1837 1838 ZERO(pFile); 1839 1840 // copy open flags 1841 pFile->flOpenMode = flOpenMode; 1842 1843 if (!(arc = DosOpen((PSZ)pcszFilename, 1844 &pFile->hf, 1845 &ulAction, 1846 *pcbFile, 1847 FILE_ARCHIVED, 1848 fsOpenFlags, 1849 fsOpenMode, 1850 NULL))) // EAs 1834 1851 { 1835 ULONG ulAction; 1836 1837 ZERO(pFile); 1838 1839 // copy open flags 1840 pFile->flOpenMode = flOpenMode; 1841 1842 if (!(arc = DosOpen((PSZ)pcszFilename, 1843 &pFile->hf, 1844 &ulAction, 1845 *pcbFile, 1846 FILE_ARCHIVED, 1847 fsOpenFlags, 1848 fsOpenMode, 1849 NULL))) // EAs 1850 { 1851 // alright, got the file: 1852 1853 if ( (ulAction == FILE_EXISTED) 1854 && ((flOpenMode & XOPEN_ACCESS_MASK) == XOPEN_READWRITE_APPEND) 1855 ) 1856 // get its size and set ptr to end for append 1857 arc = DosSetFilePtr(pFile->hf, 1858 0, 1859 FILE_END, 1852 // alright, got the file: 1853 1854 if ( (ulAction == FILE_EXISTED) 1855 && ((flOpenMode & XOPEN_ACCESS_MASK) == XOPEN_READWRITE_APPEND) 1856 ) 1857 // get its size and set ptr to end for append 1858 arc = DosSetFilePtr(pFile->hf, 1859 0, 1860 FILE_END, 1861 pcbFile); 1862 else 1863 arc = doshQueryFileSize(pFile->hf, 1860 1864 pcbFile); 1861 else 1862 arc = doshQueryFileSize(pFile->hf, 1863 pcbFile); 1864 // file ptr is at beginning 1865 1866 // store file size 1867 pFile->cbInitial 1868 = pFile->cbCurrent 1869 = *pcbFile; 1870 } 1871 1872 if (arc) 1873 doshClose(&pFile); 1874 else 1875 *ppFile = pFile; 1865 // file ptr is at beginning 1866 1867 if (arc) 1868 _Pmpf((__FUNCTION__ ": DosSetFilePtr/queryfilesize returned %d for %s", 1869 arc, pcszFilename)); 1870 1871 // store file size 1872 pFile->cbInitial 1873 = pFile->cbCurrent 1874 = *pcbFile; 1876 1875 } 1877 1876 else 1878 arc = ERROR_NOT_ENOUGH_MEMORY; 1877 _Pmpf((__FUNCTION__ ": DosOpen returned %d for %s", 1878 arc, pcszFilename)); 1879 1880 if (arc) 1881 doshClose(&pFile); 1882 else 1883 *ppFile = pFile; 1879 1884 } 1880 1885 else 1881 arc = ERROR_INVALID_PARAMETER; 1882 } 1886 arc = ERROR_NOT_ENOUGH_MEMORY; 1887 } 1888 else 1889 arc = ERROR_INVALID_PARAMETER; 1883 1890 1884 1891 return (arc); -
trunk/src/helpers/dosh2.c
r124 r126 552 552 cbRead = sizeof(PEHEADER); 553 553 554 if (!(pbHeader = malloc(cbRead)))554 if (!(pbHeader = (PBYTE)malloc(cbRead))) 555 555 arc = ERROR_NOT_ENOUGH_MEMORY; 556 556 else if (!(arc = doshReadAt(hFile, -
trunk/src/helpers/gpih.c
r111 r126 62 62 // array for querying device capabilities (gpihQueryDisplayCaps) 63 63 LONG DisplayCaps[CAPS_DEVICE_POLYSET_POINTS] = {0}; 64 BOOL fCapsQueried = FALSE;64 BOOL G_fCapsQueried = FALSE; 65 65 66 66 /* … … 171 171 * This function will load all the device capabilities 172 172 * only once into a global array and re-use them afterwards. 173 * 174 *@@changed V0.9.16 (2001-12-18) [umoeller]: fixed multiple loads 173 175 */ 174 176 175 177 ULONG gpihQueryDisplayCaps(ULONG ulIndex) 176 178 { 177 if (! fCapsQueried)179 if (!G_fCapsQueried) 178 180 { 179 181 HPS hps = WinGetScreenPS(HWND_DESKTOP); 180 182 HDC hdc = GpiQueryDevice(hps); 181 183 DevQueryCaps(hdc, 0, CAPS_DEVICE_POLYSET_POINTS, &DisplayCaps[0]); 184 G_fCapsQueried = TRUE; // was missing V0.9.16 (2001-12-18) [umoeller] 182 185 } 183 186 … … 1459 1462 /* 1460 1463 *@@ gpihCreateBitmap: 1464 * calls gpihCreateBitmap2 with cPlanes and cBitCount == 0 1465 * for compatibility with exports. Widgets might 1466 * have used this func. 1467 * 1468 *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy 1469 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateBitmap2 1470 */ 1471 1472 HBITMAP gpihCreateBitmap(HPS hpsMem, // in: memory DC 1473 ULONG cx, // in: width of new bitmap 1474 ULONG cy) // in: height of new bitmap 1475 { 1476 return (gpihCreateBitmap2(hpsMem, 1477 cx, 1478 cy, 1479 0, 1480 0)); // current screen bit count 1481 } 1482 1483 /* 1484 *@@ gpihCreateBitmap2: 1461 1485 * creates a new bitmap for a given memory PS. 1462 1486 * This bitmap will have the cPlanes and bitcount … … 1472 1496 * Returns the bitmap handle or NULLHANDLE upon errors. 1473 1497 * 1474 *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy 1475 */ 1476 1477 HBITMAP gpihCreateBitmap(HPS hpsMem, // in: memory DC 1478 ULONG cx, // in: width of new bitmap 1479 ULONG cy) // in: height of new bitmap 1498 *@@added V0.9.16 (2001-12-18) [umoeller] 1499 */ 1500 1501 HBITMAP gpihCreateBitmap2(HPS hpsMem, // in: memory DC 1502 ULONG cx, // in: width of new bitmap 1503 ULONG cy, // in: height of new bitmap 1504 ULONG cPlanes, // in: color planes (usually 1); if 0, current screen is used 1505 ULONG cBitCount) // in: either 1, 4, or 24; if 0, current screen value 1480 1506 { 1481 1507 HBITMAP hbm = NULLHANDLE; 1482 1508 LONG alData[2]; 1483 1509 BITMAPINFOHEADER2 bih2; 1484 PBITMAPINFO2 pbmi = NULL;1510 // PBITMAPINFO2 pbmi = NULL; 1485 1511 1486 1512 // determine the device's plane/bit-count format; … … 1493 1519 bih2.cx = cx; // (prcl->xRight - prcl->xLeft); changed V0.9.0 1494 1520 bih2.cy = cy; // (prcl->yTop - prcl->yBottom); changed V0.9.0 1495 bih2.cPlanes = alData[0]; 1496 bih2.cBitCount = alData[1]; 1521 bih2.cPlanes = (cPlanes) ? cPlanes : alData[0]; 1522 bih2.cBitCount = (cBitCount) ? cBitCount : alData[1]; 1523 _Pmpf((__FUNCTION__ ": cPlanes %d, cBitCount %d", 1524 bih2.cPlanes, bih2.cBitCount)); 1497 1525 bih2.ulCompression = BCA_UNCOMP; 1498 1526 bih2.cbImage = ( ( (bih2.cx … … 1515 1543 bih2.ulIdentifier = 0; // application-specific data 1516 1544 1517 // allocate memory for info header 1518 if (DosAllocMem((PPVOID)&pbmi, 1519 sizeof(BITMAPINFO2) + 1520 (sizeof(RGB2) 1521 * (1 << bih2.cPlanes) 1522 * (1 << bih2.cBitCount) 1523 ), 1524 PAG_COMMIT | PAG_READ | PAG_WRITE) 1525 == NO_ERROR) 1526 { 1527 pbmi->cbFix = bih2.cbFix; 1528 pbmi->cx = bih2.cx; 1529 pbmi->cy = bih2.cy; 1530 pbmi->cPlanes = bih2.cPlanes; 1531 pbmi->cBitCount = bih2.cBitCount; 1532 pbmi->ulCompression = BCA_UNCOMP; 1533 pbmi->cbImage = ((bih2.cx+31)/32) * bih2.cy; 1534 pbmi->cxResolution = 70; 1535 pbmi->cyResolution = 70; 1536 pbmi->cclrUsed = 2; 1537 pbmi->cclrImportant = 0; 1538 pbmi->usUnits = BRU_METRIC; 1539 pbmi->usReserved = 0; 1540 pbmi->usRecording = BRA_BOTTOMUP; 1541 pbmi->usRendering = BRH_NOTHALFTONED; 1542 pbmi->cSize1 = 0; 1543 pbmi->cSize2 = 0; 1544 pbmi->ulColorEncoding = BCE_RGB; 1545 pbmi->ulIdentifier = 0; 1546 1547 // create a bit map that is compatible with the display 1548 hbm = GpiCreateBitmap(hpsMem, 1549 &bih2, 1550 FALSE, 1551 NULL, 1552 pbmi); 1553 1554 // free the memory we allocated previously; GPI has 1555 // allocated all the resources it needs itself, so 1556 // we can release this 1557 DosFreeMem(pbmi); 1558 } 1545 // create a bit map that is compatible with the display 1546 hbm = GpiCreateBitmap(hpsMem, 1547 &bih2, 1548 0, // do not initialize 1549 NULL, 1550 NULL); 1559 1551 } 1560 1552 … … 2086 2078 /* 2087 2079 *@@ gpihCreateXBitmap: 2080 * calls gpihCreateXBitmap2 with cPlanes and cBitCount == 0 2081 * for compatibility with exports. Widgets might 2082 * have used this func. 2083 * 2084 *@@added V0.9.12 (2001-05-20) [umoeller] 2085 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateXBitmap2 2086 */ 2087 2088 PXBITMAP gpihCreateXBitmap(HAB hab, // in: anchor block 2089 LONG cx, // in: bitmap width 2090 LONG cy) // in: bitmap height 2091 { 2092 return (gpihCreateXBitmap2(hab, 2093 cx, 2094 cy, 2095 0, 2096 0)); 2097 } 2098 2099 /* 2100 *@@ gpihCreateXBitmap: 2088 2101 * creates an XBitmap, which is returned in an 2089 2102 * _XBITMAP structure. … … 2124 2137 * to more than 100 lines. 2125 2138 * 2126 *@@added V0.9.12 (2001-05-20) [umoeller] 2127 */ 2128 2129 PXBITMAP gpihCreateXBitmap(HAB hab, // in: anchor block 2130 LONG cx, // in: bitmap width 2131 LONG cy) // in: bitmap height 2139 *@@added V0.9.16 (2001-12-18) [umoeller] 2140 */ 2141 2142 PXBITMAP gpihCreateXBitmap2(HAB hab, // in: anchor block 2143 LONG cx, // in: bitmap width 2144 LONG cy, // in: bitmap height 2145 ULONG cPlanes, // in: color planes (usually 1); if 0, current screen is used 2146 ULONG cBitCount) // in: either 1, 4, or 24; if 0, current screen value 2132 2147 { 2133 2148 BOOL fOK = FALSE; … … 2145 2160 &pbmp->hpsMem)) 2146 2161 { 2147 gpihSwitchToRGB(pbmp->hpsMem); 2148 if (pbmp->hbm = gpihCreateBitmap(pbmp->hpsMem, 2149 cx, 2150 cy)) 2162 if (cBitCount != 1) 2163 // not monochrome bitmap: 2164 gpihSwitchToRGB(pbmp->hpsMem); 2165 2166 if (pbmp->hbm = gpihCreateBitmap2(pbmp->hpsMem, 2167 cx, 2168 cy, 2169 cPlanes, 2170 cBitCount)) 2151 2171 { 2152 2172 if (GpiSetBitmap(pbmp->hpsMem, … … 2162 2182 2163 2183 return (pbmp); 2184 } 2185 2186 /* 2187 *@@ gpihDetachBitmap: 2188 * "detaches" the bitmap from the given XBITMAP. 2189 * This will deselect the bitmap from the internal 2190 * memory PS so it can be used with many OS/2 APIs 2191 * that require that the bitmap not be selected 2192 * into any memory PS. 2193 * 2194 * Note that it then becomes the responsibility 2195 * of the caller to explicitly call GpiDeleteBitmap 2196 * because it will not be deleted by gpihDestroyXBitmap. 2197 * 2198 *@@added V0.9.16 (2001-12-18) [umoeller] 2199 */ 2200 2201 HBITMAP gpihDetachBitmap(PXBITMAP pbmp) 2202 { 2203 HBITMAP hbm = pbmp->hbm; 2204 pbmp->hbm = NULLHANDLE; 2205 GpiSetBitmap(pbmp->hpsMem, NULLHANDLE); 2206 2207 return (hbm); 2164 2208 } 2165 2209
Note:
See TracChangeset
for help on using the changeset viewer.