From 3437f881c4270fc52365b507100f36afe837aee5 Mon Sep 17 00:00:00 2001 From: David Webster Date: Fri, 5 Apr 2002 22:09:25 +0000 Subject: [PATCH] Catching up to new common class interfaces. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/os2/toolbar.h | 7 +- include/wx/os2/toplevel.h | 2 +- include/wx/os2/window.h | 1 + src/os2/bitmap.cpp | 798 +++++++++++++++++++++++--------------- src/os2/dataobj.cpp | 4 +- src/os2/frame.cpp | 6 +- src/os2/listbox.cpp | 39 +- src/os2/makefile.va | 16 +- src/os2/thread.cpp | 13 +- src/os2/toolbar.cpp | 12 +- src/os2/toplevel.cpp | 15 +- src/os2/window.cpp | 21 +- 12 files changed, 584 insertions(+), 350 deletions(-) diff --git a/include/wx/os2/toolbar.h b/include/wx/os2/toolbar.h index 566bbb530a..12d177e51e 100644 --- a/include/wx/os2/toolbar.h +++ b/include/wx/os2/toolbar.h @@ -85,9 +85,10 @@ protected: virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); virtual wxToolBarToolBase* CreateTool( int vId - ,const wxBitmap& rBitmap1 - ,const wxBitmap& rBitmap2 - ,bool bToggle + ,const wxString& rsLabel + ,const wxBitmap& rBitmapNormal + ,const wxBitmap& rBitmapDisabled + ,wxItemKind vKind ,wxObject* pClientData ,const wxString& rShortHelpString ,const wxString& rLongHelpString diff --git a/include/wx/os2/toplevel.h b/include/wx/os2/toplevel.h index 4224ed63b7..e9045aacf6 100644 --- a/include/wx/os2/toplevel.h +++ b/include/wx/os2/toplevel.h @@ -67,7 +67,7 @@ public: virtual void Restore(void); virtual void SendSizeEvent(void); virtual void SetIcon(const wxIcon& rIcon); - inline virtual void SetIcons(const wxIconBundle& icons) { SetIcon( icons.GetIcon( -1 ) ); } + virtual void SetIcons(const wxIconBundle& rIcons); virtual bool Show(bool bShow = TRUE); virtual bool ShowFullScreen( bool bShow diff --git a/include/wx/os2/window.h b/include/wx/os2/window.h index bffba1d0b3..f225147eac 100644 --- a/include/wx/os2/window.h +++ b/include/wx/os2/window.h @@ -496,6 +496,7 @@ protected: bool m_bBackgroundTransparent:1; bool m_bMouseInWindow:1; bool m_bDoubleClickAllowed:1; + bool m_bLastKeydownProcessed:1; bool m_bWinCaptured:1; WXDWORD m_dwExStyle; diff --git a/src/os2/bitmap.cpp b/src/os2/bitmap.cpp index 285a736eda..1ca4781c1d 100644 --- a/src/os2/bitmap.cpp +++ b/src/os2/bitmap.cpp @@ -68,7 +68,7 @@ void wxBitmapRefData::Free() if (m_hBitmap) { - if ( !::GpiDeleteBitmap((HBITMAP)m_hBitmap) ) + if (!::GpiDeleteBitmap((HBITMAP)m_hBitmap)) { wxLogLastError("GpiDeleteBitmap(hbitmap)"); } @@ -85,10 +85,6 @@ void wxBitmapRefData::Free() // this function should be called from all wxBitmap ctors void wxBitmap::Init() { - // m_refData = NULL; done in the base class ctor - - if (wxTheBitmapList) - wxTheBitmapList->AddBitmap(this); } // end of wxBitmap::Init bool wxBitmap::CopyFromIconOrCursor( @@ -147,15 +143,13 @@ bool wxBitmap::CopyFromIcon( wxBitmap::~wxBitmap() { - if (wxTheBitmapList) - wxTheBitmapList->DeleteObject(this); } // end of wxBitmap::~wxBitmap wxBitmap::wxBitmap( const char zBits[] -, int nTheWidth -, int nTheHeight -, int nNoBits +, int nWidth +, int nHeight +, int nDepth ) { Init(); @@ -167,48 +161,104 @@ wxBitmap::wxBitmap( HPS hPs; DEVOPENSTRUC vDop = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL }; SIZEL vSize = {0, 0}; + char* pzData; wxASSERT(vHabmain != NULL); - hDc = ::DevOpenDC(vHabmain, OD_MEMORY, (PSZ)"*", 1L, (PDEVOPENDATA)&vDop, 0L); + m_refData = pRefData; - vHeader.cbFix = sizeof(vHeader); - vHeader.cx = (USHORT)nTheWidth; - vHeader.cy = (USHORT)nTheHeight; - vHeader.cPlanes = 1L; - vHeader.cBitCount = nNoBits; - vHeader.ulCompression = BCA_UNCOMP; - vHeader.cxResolution = 0; - vHeader.cyResolution = 0; - vHeader.cclrUsed = 0; - vHeader.cclrImportant = 0; - vHeader.usUnits = BRU_METRIC; - vHeader.usRecording = BRA_BOTTOMUP; - vHeader.usRendering = BRH_NOTHALFTONED; - vHeader.cSize1 = 0; - vHeader.cSize2 = 0; - vHeader.ulColorEncoding = 0; - vHeader.ulIdentifier = 0; + pRefData->m_nWidth = nWidth; + pRefData->m_nHeight = nHeight; + pRefData->m_nDepth = nDepth; + pRefData->m_nNumColors = 0; + pRefData->m_pSelectedInto = NULL; + hDc = ::DevOpenDC(vHabmain, OD_MEMORY, (PSZ)"*", 1L, (PDEVOPENDATA)&vDop, 0L); hPs = ::GpiCreatePS(vHabmain, hDc, &vSize, GPIA_ASSOC | PU_PELS); if (hPs == 0) { wxLogLastError("GpiCreatePS Failure"); } - m_refData = pRefData; + if (nDepth == 1) + { + // + // We assume that it is in XBM format which is not quite the same as + // the format CreateBitmap() wants because the order of bytes in the + // line is inversed! + // + const size_t nBytesPerLine = (nWidth + 7) / 8; + const size_t nPadding = nBytesPerLine % 2; + const size_t nLen = nHeight * (nPadding + nBytesPerLine); + const char* pzSrc = zBits; + int nRows; + size_t nCols; + + pzData = (char *)malloc(nLen); + + char* pzDst = pzData; + + for (nRows = 0; nRows < nHeight; nRows++) + { + for (nCols = 0; nCols < nBytesPerLine; nCols++) + { + unsigned char ucVal = *pzSrc++; + unsigned char ucReversed = 0; + int nBits; - pRefData->m_nWidth = nTheWidth; - pRefData->m_nHeight = nTheHeight; - pRefData->m_nDepth = nNoBits; - pRefData->m_nNumColors = 0; - pRefData->m_pSelectedInto = NULL; + for (nBits = 0; nBits < 8; nBits++) + { + ucReversed <<= 1; + ucReversed |= (ucVal & 0x01); + ucVal >>= 1; + } + *pzDst++ = ucReversed; + } + if (nPadding) + *pzDst++ = 0; + } + } + else + { + // + // Bits should already be in Windows standard format + // + pzData = (char *)zBits; // const_cast is harmless + } + + memset(&vHeader, '\0', sizeof(BITMAPINFOHEADER2)); + vHeader.cbFix = sizeof(vHeader); + vHeader.cx = (USHORT)nWidth; + vHeader.cy = (USHORT)nHeight; + vHeader.cPlanes = 1L; + vHeader.cBitCount = nDepth; + vHeader.usReserved = 0; + vHeader.ulCompression = BCA_UNCOMP; + vHeader.usRecording = BRA_BOTTOMUP; + vHeader.usRendering = BRH_NOTHALFTONED; + vHeader.ulColorEncoding = BCE_RGB; + vHeader.ulIdentifier = 0; + + memset(&vInfo, '\0', sizeof(BITMAPINFO2)); + vInfo.cbFix = sizeof(vInfo); + vInfo.cx = (USHORT)nWidth; + vInfo.cy = (USHORT)nHeight; + vInfo.cPlanes = 1L; + vInfo.cBitCount = nDepth; + vInfo.usReserved = 0; + vInfo.ulCompression = BCA_UNCOMP; + vInfo.usRecording = BRA_BOTTOMUP; + vInfo.usRendering = BRH_NOTHALFTONED; + vInfo.ulColorEncoding = BCE_RGB; + vInfo.ulIdentifier = 0; + + HBITMAP hBmp = ::GpiCreateBitmap(hPs, &vHeader, CBM_INIT, (PBYTE)pzData, &vInfo); - HBITMAP hBmp = ::GpiCreateBitmap(hPs, &vHeader, 0L, NULL, &vInfo); if (!hBmp) { wxLogLastError("CreateBitmap"); } + ::WinReleasePS(hPs); SetHBITMAP((WXHBITMAP)hBmp); } // end of wxBitmap::wxBitmap @@ -460,335 +510,493 @@ bool wxBitmap::SaveFile( // wxImage-wxBitmap convertion // ---------------------------------------------------------------------------- -bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) +bool wxBitmap::CreateFromImage ( + const wxImage& rImage +, int nDepth +) { - wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ) - -// TODO: -/* - int sizeLimit = 1024*768*3; - - // width and height of the device-dependent bitmap - int width = GetWidth(); - int bmpHeight = GetHeight(); - - // calc the number of bytes per scanline and padding - int bytePerLine = width*3; - int sizeDWORD = sizeof( DWORD ); - int lineBoundary = bytePerLine % sizeDWORD; - int padding = 0; - if( lineBoundary > 0 ) + wxCHECK_MSG(rImage.Ok(), FALSE, wxT("invalid image")); + + int nSizeLimit = 1024 * 768 * 3; + int nWidth = GetWidth(); + int nBmpHeight = GetHeight(); + int nBytePerLine = nWidth * 3; + int nSizeDWORD = sizeof(DWORD); + int nLineBoundary = nBytePerLine % nSizeDWORD; + int nPadding = 0; + + if (nLineBoundary > 0) { - padding = sizeDWORD - lineBoundary; - bytePerLine += padding; + nPadding = nSizeDWORD - nLineBoundary; + nBytePerLine += nPadding; } - // calc the number of DIBs and heights of DIBs - int numDIB = 1; - int hRemain = 0; - int height = sizeLimit/bytePerLine; - if( height >= bmpHeight ) - height = bmpHeight; + + // + // Calc the number of DIBs and heights of DIBs + // + int nNumDIB = 1; + int nHRemain = 0; + int nHeight = nSizeLimit / nBytePerLine; + + if (nHeight >= nBmpHeight) + nHeight = nBmpHeight; else { - numDIB = bmpHeight / height; - hRemain = bmpHeight % height; - if( hRemain >0 ) numDIB++; + nNumDIB = nBmpHeight / nHeight; + nHRemain = nBmpHeight % nHeight; + if (nHRemain > 0) + nNumDIB++; } - // set bitmap parameters - wxBitmap bitmap; - wxCHECK_MSG( Ok(), bitmap, wxT("invalid image") ); - bitmap.SetWidth( width ); - bitmap.SetHeight( bmpHeight ); - bitmap.SetDepth( wxDisplayDepth() ); - - // create a DIB header - int headersize = sizeof(BITMAPINFOHEADER); - LPBITMAPINFO lpDIBh = (BITMAPINFO *) malloc( headersize ); - wxCHECK_MSG( lpDIBh, bitmap, wxT("could not allocate memory for DIB header") ); + // + // Set bitmap parameters + // + wxCHECK_MSG(rImage.Ok(), FALSE, wxT("invalid image")); + SetWidth(nWidth); + SetHeight(nBmpHeight); + if (nDepth == -1) + nDepth = wxDisplayDepth(); + SetDepth(nDepth); + +#if wxUSE_PALETTE + // + // Copy the palette from the source image + // + SetPalette(rImage.GetPalette()); +#endif // wxUSE_PALETTE + + // + // Create a DIB header + // + BITMAPINFOHEADER2 vHeader; + + // // Fill in the DIB header - lpDIBh->bmiHeader.biSize = headersize; - lpDIBh->bmiHeader.biWidth = (DWORD)width; - lpDIBh->bmiHeader.biHeight = (DWORD)(-height); - lpDIBh->bmiHeader.biSizeImage = bytePerLine*height; - // the general formula for biSizeImage: - // ( ( ( ((DWORD)width*24) +31 ) & ~31 ) >> 3 ) * height; - lpDIBh->bmiHeader.biPlanes = 1; - lpDIBh->bmiHeader.biBitCount = 24; - lpDIBh->bmiHeader.biCompression = BI_RGB; - lpDIBh->bmiHeader.biClrUsed = 0; + // + memset(&vHeader, '\0', sizeof(BITMAPINFOHEADER2)); + vHeader.cbFix = sizeof(vHeader); + vHeader.cx = (USHORT)nWidth; + vHeader.cy = (USHORT)nHeight; + vHeader.cPlanes = 1L; + vHeader.cBitCount = 24; + vHeader.ulCompression = BCA_UNCOMP; + vHeader.cbImage = nBytePerLine * nHeight; + vHeader.cclrUsed = 0; + + // // These seem not really needed for our purpose here. - lpDIBh->bmiHeader.biClrImportant = 0; - lpDIBh->bmiHeader.biXPelsPerMeter = 0; - lpDIBh->bmiHeader.biYPelsPerMeter = 0; - // memory for DIB data - unsigned char *lpBits; - lpBits = (unsigned char *)malloc( lpDIBh->bmiHeader.biSizeImage ); - if( !lpBits ) + // + vHeader.cxResolution = 0; + vHeader.cyResolution = 0; + vHeader.cclrImportant = 0; + vHeader.usUnits = BRU_METRIC; + vHeader.usReserved = 0; + vHeader.cSize1 = 0; + vHeader.cSize2 = 0; + vHeader.usRecording = BRA_BOTTOMUP; + vHeader.usRendering = BRH_NOTHALFTONED; + vHeader.ulColorEncoding = BCE_RGB; + vHeader.ulIdentifier = 0; + + // + // Memory for DIB data + // + unsigned char* pucBits; + + pucBits = (unsigned char *)malloc(vHeader.cbImage); + if(!pucBits) + { + wxFAIL_MSG(wxT("could not allocate memory for DIB")); + return FALSE; + } + + // + // Create and set the device-dependent bitmap + // + DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; + SIZEL vSize = {0, 0}; + HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); + HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); + HBITMAP hBmp; + HBITMAP hBmpOld; + + hBmp = ::GpiCreateBitmap( hPS + ,&vHeader + ,0L + ,NULL + ,NULL + ); + hBmpOld = ::GpiSetBitmap(hPS, hBmp); +#if wxUSE_PALETTE + HPAL hOldPalette = NULLHANDLE; + if (rImage.GetPalette().Ok()) { - wxFAIL_MSG( wxT("could not allocate memory for DIB") ); - free( lpDIBh ); - return bitmap; + hOldPalette = ::GpiSelectPalette(hPS, (HPAL)rImage.GetPalette().GetHPALETTE()); } +#endif // wxUSE_PALETTE - // create and set the device-dependent bitmap - HDC hdc = ::GetDC(NULL); - HDC memdc = ::CreateCompatibleDC( hdc ); - HBITMAP hbitmap; - hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight ); - ::SelectObject( memdc, hbitmap); - - // copy image data into DIB data and then into DDB (in a loop) - unsigned char *data = GetData(); - int i, j, n; - int origin = 0; - unsigned char *ptdata = data; - unsigned char *ptbits; - - for( n=0; n 1 && n == numDIB-1 && hRemain > 0 ) + if (nNumDIB > 1 && n == nNumDIB - 1 && nHRemain > 0) { - // redefine height and size of the (possibly) last smaller DIB + // + // Redefine height and size of the (possibly) last smaller DIB // memory is not reallocated - height = hRemain; - lpDIBh->bmiHeader.biHeight = (DWORD)(-height); - lpDIBh->bmiHeader.biSizeImage = bytePerLine*height; + // + nHeight = nHRemain; + vHeader.cy = (DWORD)(nHeight); + vHeader.cbImage = nBytePerLine * nHeight; } - ptbits = lpBits; - - for( j=0; jbmiHeader), CBM_INIT, lpBits, lpDIBh, DIB_RGB_COLORS ); - // The above line is equivalent to the following two lines. - // hbitmap = ::CreateCompatibleBitmap( hdc, width, height ); - // ::SetDIBits( hdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS); - // or the following lines - // hbitmap = ::CreateCompatibleBitmap( hdc, width, height ); - // HDC memdc = ::CreateCompatibleDC( hdc ); - // ::SelectObject( memdc, hbitmap); - // ::SetDIBitsToDevice( memdc, 0, 0, width, height, - // 0, 0, 0, height, (void *)lpBits, lpDIBh, DIB_RGB_COLORS); - // ::SelectObject( memdc, 0 ); - // ::DeleteDC( memdc ); + + // + // Have to do something similar to WIN32's StretchDIBits, use GpiBitBlt + // + POINTL vPoint[4] = { 0, nOrigin, + nWidth, nHeight, + 0, 0, nWidth, nHeight + }; + + ::GpiBitBlt( hPS + ,hPS + ,4 + ,vPoint + ,ROP_SRCCOPY + ,BBO_IGNORE + ); + nOrigin += nHeight; } - bitmap.SetHBITMAP( (WXHBITMAP) hbitmap ); + SetHBITMAP((WXHBITMAP)hBmp); +#if wxUSE_PALETTE + if (hOldPalette) + ::GpiSelectPalette(hPS, hOldPalette); +#endif // wxUSE_PALETTE - // similarly, created an mono-bitmap for the possible mask - if( HasMask() ) + // + // Similarly, created an mono-bitmap for the possible mask + // + if (rImage.HasMask()) { - hbitmap = ::CreateBitmap( (WORD)width, (WORD)bmpHeight, 1, 1, NULL ); - ::SelectObject( memdc, hbitmap); - if( numDIB == 1 ) height = bmpHeight; - else height = sizeLimit/bytePerLine; - lpDIBh->bmiHeader.biHeight = (DWORD)(-height); - lpDIBh->bmiHeader.biSizeImage = bytePerLine*height; - origin = 0; - unsigned char r = GetMaskRed(); - unsigned char g = GetMaskGreen(); - unsigned char b = GetMaskBlue(); - unsigned char zero = 0, one = 255; - ptdata = data; - for( n=0; n 1 && n == numDIB - 1 && hRemain > 0 ) + if (nNumDIB > 1 && n == nNumDIB - 1 && nHRemain > 0) { - // redefine height and size of the (possibly) last smaller DIB + // + // Redefine height and size of the (possibly) last smaller DIB // memory is not reallocated - height = hRemain; - lpDIBh->bmiHeader.biHeight = (DWORD)(-height); - lpDIBh->bmiHeader.biSizeImage = bytePerLine*height; + // + nHeight = nHRemain; + vHeader.cy = (DWORD)(nHeight); + vHeader.cbImage = nBytePerLine * nHeight; } - ptbits = lpBits; - for( int j=0; jSetMaskBitmap( (WXHBITMAP) hbitmap ); - bitmap.SetMask( mask ); - } - // free allocated resources - ::SelectObject( memdc, 0 ); - ::DeleteDC( memdc ); - ::ReleaseDC(NULL, hdc); - free(lpDIBh); - free(lpBits); + // + // Create a wxMask object + // + wxMask* pMask = new wxMask(); - // check the wxBitmap object - if( bitmap.GetHBITMAP() ) - bitmap.SetOk( TRUE ); - else - bitmap.SetOk( FALSE ); -*/ + pMask->SetMaskBitmap((WXHBITMAP)hBmp); + SetMask(pMask); + hBmpOld = ::GpiSetBitmap(hPS, hBmp); + } + // + // Free allocated resources + // + ::GpiSetBitmap(hPS, NULLHANDLE); + ::GpiDestroyPS(hPS); + ::DevCloseDC(hDC); + free(pucBits); return TRUE; -} +} // end of wxBitmap::CreateFromImage wxImage wxBitmap::ConvertToImage() const { - wxImage image; + wxImage vImage; wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); - // create an wxImage object - int width = GetWidth(); - int height = GetHeight(); - image.Create( width, height ); - unsigned char *data = image.GetData(); - if( !data ) + // + // Create an wxImage object + // + int nWidth = GetWidth(); + int nHeight = GetHeight(); + int nDevWidth; + int nDevHeight; + int nBytePerLine = nWidth * 3; + int nSizeDWORD = sizeof(DWORD); + int nLineBoundary = nBytePerLine % nSizeDWORD; + int nPadding = 0; + unsigned char* pData; + unsigned char* lpBits; + long lScans; + BITMAPINFOHEADER2 vDIBh; + BITMAPINFO2 vDIBInfo; + HDC hDCMem; + PSZ pszData[4] = { "Display", NULL, NULL, NULL }; + HPS hPSMem; + HPS hPS; + SIZEL vSizlPage = {0,0}; + HBITMAP hBitmap; + + vImage.Create( nWidth + ,nHeight + ); + pData = vImage.GetData(); + if(!pData) { wxFAIL_MSG( wxT("could not allocate data for image") ); return wxNullImage; } - - // calc the number of bytes per scanline and padding in the DIB - int bytePerLine = width*3; - int sizeDWORD = sizeof( DWORD ); - int lineBoundary = bytePerLine % sizeDWORD; - int padding = 0; - if( lineBoundary > 0 ) - { - padding = sizeDWORD - lineBoundary; - bytePerLine += padding; - } -// TODO: -/* - // create a DIB header - int headersize = sizeof(BITMAPINFOHEADER); - LPBITMAPINFO lpDIBh = (BITMAPINFO *) malloc( headersize ); - if( !lpDIBh ) + if(nLineBoundary > 0) { - wxFAIL_MSG( wxT("could not allocate data for DIB header") ); - free( data ); - return; + nPadding = nSizeDWORD - nLineBoundary; + nBytePerLine += nPadding; } - // Fill in the DIB header - lpDIBh->bmiHeader.biSize = headersize; - lpDIBh->bmiHeader.biWidth = width; - lpDIBh->bmiHeader.biHeight = -height; - lpDIBh->bmiHeader.biSizeImage = bytePerLine * height; - lpDIBh->bmiHeader.biPlanes = 1; - lpDIBh->bmiHeader.biBitCount = 24; - lpDIBh->bmiHeader.biCompression = BI_RGB; - lpDIBh->bmiHeader.biClrUsed = 0; - // These seem not really needed for our purpose here. - lpDIBh->bmiHeader.biClrImportant = 0; - lpDIBh->bmiHeader.biXPelsPerMeter = 0; - lpDIBh->bmiHeader.biYPelsPerMeter = 0; - // memory for DIB data - unsigned char *lpBits; - lpBits = (unsigned char *) malloc( lpDIBh->bmiHeader.biSizeImage ); - if( !lpBits ) + wxDisplaySize( &nDevWidth + ,&nDevHeight + ); + // + // Create and fill a DIB header + // + memset(&vDIBh, '\0', sizeof(BITMAPINFOHEADER2)); + vDIBh.cbFix = sizeof(BITMAPINFOHEADER2); + vDIBh.cx = nWidth; + vDIBh.cy = nHeight; + vDIBh.cPlanes = 1; + vDIBh.cbImage = nBytePerLine * nHeight; + vDIBh.cBitCount = 24; + + memset(&vDIBInfo, '\0', sizeof(BITMAPINFO2)); + vDIBInfo.cbFix = sizeof(BITMAPINFO2); + vDIBInfo.cPlanes = 1; + vDIBInfo.cBitCount = 24; + vDIBInfo.ulCompression = BCA_UNCOMP; + vDIBInfo.usReserved = 0; + vDIBInfo.usRecording = BRA_BOTTOMUP; + vDIBInfo.usRendering = BRH_NOTHALFTONED; + vDIBInfo.ulColorEncoding = BCE_RGB; + vDIBInfo.ulIdentifier = 0; + + lpBits = (unsigned char *)malloc(vDIBh.cbImage); + if (!lpBits) { - wxFAIL_MSG( wxT("could not allocate data for DIB") ); - free( data ); - free( lpDIBh ); - return; + wxFAIL_MSG(wxT("could not allocate data for DIB")); + free(pData); + return wxNullImage; } - // copy data from the device-dependent bitmap to the DIB - HDC hdc = ::GetDC(NULL); - HBITMAP hbitmap; - hbitmap = (HBITMAP) bitmap.GetHBITMAP(); - ::GetDIBits( hdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS ); - - // copy DIB data into the wxImage object - int i, j; - unsigned char *ptdata = data; - unsigned char *ptbits = lpBits; - for( i=0; iGetMaskBitmap() ) + // + // Similarly, set data according to the possible mask bitmap + // + if (GetMask() && GetMask()->GetMaskBitmap()) { - hbitmap = (HBITMAP) bitmap.GetMask()->GetMaskBitmap(); - // memory DC created, color set, data copied, and memory DC deleted - HDC memdc = ::CreateCompatibleDC( hdc ); - ::SetTextColor( memdc, RGB( 0, 0, 0 ) ); - ::SetBkColor( memdc, RGB( 255, 255, 255 ) ); - ::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS ); - ::DeleteDC( memdc ); - // background color set to RGB(16,16,16) in consistent with wxGTK - unsigned char r=16, g=16, b=16; - ptdata = data; + hBitmap = (HBITMAP)GetMask()->GetMaskBitmap(); + + // + // Memory DC/PS created, color set, data copied, and memory DC/PS deleted + // + HDC hMemDC = ::DevOpenDC( vHabmain + ,OD_MEMORY + ,"*" + ,4 + ,(PDEVOPENDATA)pszData + ,NULLHANDLE + ); + HPS hMemPS = ::GpiCreatePS( vHabmain + ,hMemDC + ,&vSizlPage + ,PU_PELS | GPIA_ASSOC | GPIT_MICRO + ); + ::GpiSetColor(hMemPS, OS2RGB(0, 0, 0)); + ::GpiSetBackColor(hMemPS, OS2RGB(255, 255, 255) ); + ::GpiQueryBitmapBits( hPSMem + ,0L + ,(LONG)nHeight + ,(PBYTE)lpBits + ,&vDIBInfo + ); + ::GpiDestroyPS(hMemPS); + ::DevCloseDC(hMemDC); + + // + // Background color set to RGB(16,16,16) in consistent with wxGTK + // + unsigned char ucRed = 16; + unsigned char ucGreen = 16; + unsigned char ucBlue = 16; + + ptdata = pData; ptbits = lpBits; - for( i=0; im_pBitmapMask = pMask; } // end of wxBitmap::SetMask -// -// Will try something for OS/2 but not really sure how close -// to the msw intent this is. -// wxBitmap wxBitmap::GetBitmapForDC( wxDC& rDc ) const { - wxMemoryDC vMemDC; - wxBitmap vTmpBitmap( this->GetWidth() - ,this->GetHeight() - ,rDc.GetDepth() - ); - WXHBITMAP vOldBitmap; - HPS hMemoryPS; - HPS hPs; - POINTL vPoint[4]; - SIZEL vSize = {0,0}; - - hMemoryPS = ::GpiCreatePS(vHabmain, (HDC)vMemDC.GetHDC(), &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); - hPs = ::GpiCreatePS(vHabmain, (HDC)rDc.GetHDC(), &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); - - // TODO: Set the points - - vOldBitmap = (WXHBITMAP)::GpiSetBitmap(hPs, (HBITMAP)vTmpBitmap.GetHBITMAP()); - ::GpiBitBlt(hPs, hMemoryPS, 4L, vPoint, ROP_SRCCOPY, BBO_IGNORE); - - return(vTmpBitmap); + return(*this); } // end of wxBitmap::GetBitmapForDC // ---------------------------------------------------------------------------- @@ -1361,3 +1546,4 @@ HBITMAP wxInvertMask( return hBmpInvMask; } // end of WxWinGdi_InvertMask + diff --git a/src/os2/dataobj.cpp b/src/os2/dataobj.cpp index 3763a035a1..b6738a028d 100644 --- a/src/os2/dataobj.cpp +++ b/src/os2/dataobj.cpp @@ -323,7 +323,7 @@ bool wxBitmapDataObject::SetData( return FALSE; } - m_bitmap = vImage.ConvertToBitmap(); + m_bitmap = wxBitmap(vImage); #endif //wxUSE_STREAMS return m_bitmap.Ok(); @@ -335,7 +335,7 @@ void wxBitmapDataObject::DoConvertToPng() return; #if wxUSE_STREAMS - wxImage vImage(m_bitmap); + wxImage vImage = m_bitmap.ConvertToImage(); wxPNGHandler vHandler; wxCountingOutputStream vCount; diff --git a/src/os2/frame.cpp b/src/os2/frame.cpp index c2e3d87c83..f0a4438e16 100644 --- a/src/os2/frame.cpp +++ b/src/os2/frame.cpp @@ -923,9 +923,10 @@ bool wxFrame::HandlePaint() // // Icons in PM are the same as "pointers" // + const wxIcon& vIcon = GetIcon(); HPOINTER hIcon; - if (m_icon.Ok()) + if (vIcon.Ok()) hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); else hIcon = (HPOINTER)m_hDefaultIcon; @@ -1379,9 +1380,10 @@ MRESULT wxFrame::OS2WindowProc( case CM_QUERYDRAGIMAGE: { + const wxIcon& vIcon = GetIcon(); HPOINTER hIcon; - if (m_icon.Ok()) + if (vIcon.Ok()) hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L); else hIcon = (HPOINTER)m_hDefaultIcon; diff --git a/src/os2/listbox.cpp b/src/os2/listbox.cpp index 2e7ffc1757..d23bedc512 100644 --- a/src/os2/listbox.cpp +++ b/src/os2/listbox.cpp @@ -281,7 +281,7 @@ int wxListBox::DoAppend( wxOwnerDrawn* pNewItem = CreateItem(nIndex); // dummy argument pNewItem->SetName(rsItem); - m_aItems.Add(pNewItem); + m_aItems.Insert(pNewItem, nIndex); ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)((SHORT)nIndex), MPFROMP(pNewItem)); pNewItem->SetFont(GetFont()); } @@ -331,24 +331,18 @@ void wxListBox::DoSetItems( // // First delete old items // - size_t lUi = m_aItems.Count(); - - while (lUi-- != 0) - { - delete m_aItems[lUi]; - } - m_aItems.Empty(); + WX_CLEAR_ARRAY(m_aItems); // // Then create new ones // - for (lUi = 0; lUi < (size_t)m_nNumItems; lUi++) + for (size_t ui = 0; ui < (size_t)m_nNumItems; ui++) { - wxOwnerDrawn* pNewItem = CreateItem(lUi); + wxOwnerDrawn* pNewItem = CreateItem(ui); - pNewItem->SetName(raChoices[lUi]); + pNewItem->SetName(raChoices[ui]); m_aItems.Add(pNewItem); - ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lUi), MPFROMP(pNewItem)); + ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem)); } } #endif // wxUSE_OWNER_DRAWN @@ -596,8 +590,25 @@ void wxListBox::DoInsertItems( int nItems = asItems.GetCount(); for (int i = 0; i < nItems; i++) - ::WinSendMsg(GetHwnd(), LM_INSERTITEM, MPFROMLONG((LONG)(i + nPos)), (MPARAM)asItems[i].c_str()); - m_nNumItems += nItems; + { + int nIndex = (int)::WinSendMsg( GetHwnd() + ,LM_INSERTITEM + ,MPFROMLONG((LONG)(i + nPos)) + ,(MPARAM)asItems[i].c_str() + ); + + wxOwnerDrawn* pNewItem = CreateItem(nIndex); + + pNewItem->SetName(asItems[i]); + pNewItem->SetFont(GetFont()); + m_aItems.Insert(pNewItem, nIndex); + ::WinSendMsg( GetHwnd() + ,LM_SETITEMHANDLE + ,(MPARAM)((SHORT)nIndex) + ,MPFROMP(pNewItem) + ); + m_nNumItems += nItems; + } } // end of wxListBox::DoInsertItems void wxListBox::SetString( diff --git a/src/os2/makefile.va b/src/os2/makefile.va index 7ea6679d1e..003352d949 100644 --- a/src/os2/makefile.va +++ b/src/os2/makefile.va @@ -250,9 +250,11 @@ COMMONOBJS = \ ..\common\$D\hashmap.obj \ ..\common\$D\helpbase.obj \ ..\common\$D\http.obj \ + ..\common\$D\iconbndl.obj \ ..\common\$D\imagall.obj \ ..\common\$D\imagbmp.obj \ ..\common\$D\image.obj \ + ..\common\$D\imagfill.obj \ ..\common\$D\imaggif.obj \ ..\common\$D\imagiff.obj \ ..\common\$D\imagjpeg.obj \ @@ -384,9 +386,11 @@ COMLIBOBJS2 = \ hashmap.obj \ helpbase.obj \ http.obj \ + iconbndl.obj \ imagall.obj \ imagbmp.obj \ image.obj \ + imagfill.obj \ imaggif.obj \ imagiff.obj \ imagjpeg.obj \ @@ -410,11 +414,11 @@ COMLIBOBJS2 = \ mstream.obj \ nbkbase.obj \ object.obj \ - odbc.obj \ - paper.obj \ - popupcmn.obj + odbc.obj COMLIBOBJS3 = \ + paper.obj \ + popupcmn.obj \ prntbase.obj \ process.obj \ protocol.obj \ @@ -752,9 +756,11 @@ $(COMLIBOBJS2): copy ..\common\$D\hashmap.obj copy ..\common\$D\helpbase.obj copy ..\common\$D\http.obj + copy ..\common\$D\iconbndl.obj copy ..\common\$D\imagall.obj copy ..\common\$D\imagbmp.obj copy ..\common\$D\image.obj + copy ..\common\$D\imagfill.obj copy ..\common\$D\imaggif.obj copy ..\common\$D\imagiff.obj copy ..\common\$D\imagjpeg.obj @@ -779,10 +785,10 @@ $(COMLIBOBJS2): copy ..\common\$D\nbkbase.obj copy ..\common\$D\object.obj copy ..\common\$D\odbc.obj - copy ..\common\$D\paper.obj - copy ..\common\$D\popupcmn.obj $(COMLIBOBJS3): + copy ..\common\$D\paper.obj + copy ..\common\$D\popupcmn.obj copy ..\common\$D\prntbase.obj copy ..\common\$D\process.obj copy ..\common\$D\protocol.obj diff --git a/src/os2/thread.cpp b/src/os2/thread.cpp index c8cd9a7968..af2e0f7304 100644 --- a/src/os2/thread.cpp +++ b/src/os2/thread.cpp @@ -170,7 +170,7 @@ wxMutexError wxMutex::Unlock() class wxConditionInternal { public: - inline wxConditionInternal () + inline wxConditionInternal (wxMutex& rMutex) : m_vMutex(rMutex) { ::DosCreateEventSem(NULL, &m_vEvent, DC_SEM_SHARED, FALSE); if (!m_vEvent) @@ -208,14 +208,15 @@ public: HEV m_vEvent; int m_nWaiters; + wxMutex& m_vMutex; }; -wxCondition::wxCondition() +wxCondition::wxCondition(wxMutex& rMutex) { APIRET ulrc; ULONG ulCount; - m_internal = new wxConditionInternal; + m_internal = new wxConditionInternal(rMutex); ulrc = ::DosCreateEventSem(NULL, &m_internal->m_vEvent, 0L, FALSE); if (ulrc != 0) { @@ -239,10 +240,10 @@ void wxCondition::Wait() } bool wxCondition::Wait( - unsigned long lSec -, unsigned long lNsec) + unsigned long lMilliSec +) { - return m_internal->Wait(lSec*1000 + lNsec/1000000); + return m_internal->Wait(lMilliSec); } void wxCondition::Signal() diff --git a/src/os2/toolbar.cpp b/src/os2/toolbar.cpp index 24a0aa8aff..40f561de27 100644 --- a/src/os2/toolbar.cpp +++ b/src/os2/toolbar.cpp @@ -84,17 +84,19 @@ class wxToolBarTool : public wxToolBarToolBase public: inline wxToolBarTool( wxToolBar* pTbar ,int vId + ,const wxString& rsLabel ,const wxBitmap& rBitmap1 ,const wxBitmap& rBitmap2 - ,bool bToggle + ,wxItemKind vKind ,wxObject* pClientData ,const wxString& rShortHelpString ,const wxString& rLongHelpString ) : wxToolBarToolBase( pTbar ,vId + ,rsLabel ,rBitmap1 ,rBitmap2 - ,bToggle + ,vKind ,pClientData ,rShortHelpString ,rLongHelpString @@ -132,9 +134,10 @@ private: wxToolBarToolBase* wxToolBar::CreateTool( int nId +, const wxString& rsLabel , const wxBitmap& rBitmap1 , const wxBitmap& rBitmap2 -, bool bToggle +, wxItemKind vKind , wxObject* pClientData , const wxString& rShortHelpString , const wxString& rLongHelpString @@ -142,9 +145,10 @@ wxToolBarToolBase* wxToolBar::CreateTool( { return(new wxToolBarTool( this ,nId + ,rsLabel ,rBitmap1 ,rBitmap2 - ,bToggle + ,vKind ,pClientData ,rShortHelpString ,rLongHelpString diff --git a/src/os2/toplevel.cpp b/src/os2/toplevel.cpp index a77cb0a375..82cc9d5629 100644 --- a/src/os2/toplevel.cpp +++ b/src/os2/toplevel.cpp @@ -822,17 +822,26 @@ bool wxTopLevelWindowOS2::ShowFullScreen( void wxTopLevelWindowOS2::SetIcon( const wxIcon& rIcon ) +{ + SetIcons(wxIconBundle(rIcon)); +} // end of wxTopLevelWindowOS2::SetIcon + +void wxTopLevelWindowOS2::SetIcons( + const wxIconBundle& rIcons +) { // // This sets m_icon // - wxTopLevelWindowBase::SetIcon(rIcon); + wxTopLevelWindowBase::SetIcons(rIcons); + + const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32)); - if (m_icon.Ok()) + if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32) { ::WinSendMsg( m_hFrame ,WM_SETICON - ,(MPARAM)((HPOINTER)m_icon.GetHICON()) + ,(MPARAM)((HPOINTER)vIcon.GetHICON()) ,NULL ); ::WinSendMsg( m_hFrame diff --git a/src/os2/window.cpp b/src/os2/window.cpp index fd71c44b76..c5000c0f47 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -278,10 +278,11 @@ void wxWindowOS2::Init() m_bDoubleClickAllowed = 0; m_bWinCaptured = FALSE; - m_isBeingDeleted = FALSE; - m_fnOldWndProc = 0; - m_bUseCtl3D = FALSE; - m_bMouseInWindow = FALSE; + m_isBeingDeleted = FALSE; + m_fnOldWndProc = 0; + m_bUseCtl3D = FALSE; + m_bMouseInWindow = FALSE; + m_bLastKeydownProcessed = FALSE; // // wxWnd @@ -2705,12 +2706,14 @@ MRESULT wxWindowOS2::OS2WindowProc( } else // keydown event { + m_bLastKeydownProcessed = FALSE; // // If this has been processed by an event handler, // return 0 now (we've handled it). DON't RETURN // we still need to process further // HandleKeyDown((WXDWORD)wParam, lParam); + m_bLastKeydownProcessed = TRUE; if (uKeyFlags & KC_VIRTUALKEY) { USHORT uVk = SHORT2FROMMP((MPARAM)lParam); @@ -4014,6 +4017,16 @@ bool wxWindowOS2::HandleChar( bool bCtrlDown = FALSE; int vId; + if (m_bLastKeydownProcessed) + { + // + // The key was handled in the EVT_KEY_DOWN. Handling a key in an + // EVT_KEY_DOWN handler is meant, by design, to prevent EVT_CHARs + // from happening, so just bail out at this point. + // + m_bLastKeydownProcessed = FALSE; + return TRUE; + } if (isASCII) { // -- 2.45.2