From 1cee3f6006e1838fa3d59055233c435e3124d59e Mon Sep 17 00:00:00 2001
From: David Webster <Dave.Webster@bhmi.com>
Date: Fri, 26 Apr 2002 12:58:11 +0000
Subject: [PATCH] Updates to OS/2 to catch up with lib changes and for image
 processing.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/os2/slider.h   |   3 ++
 include/wx/os2/textctrl.h |   1 -
 include/wx/os2/window.h   |   1 +
 src/os2/bitmap.cpp        | 103 +++++++++++++++++++++++---------------
 src/os2/dc.cpp            |  48 ------------------
 src/os2/dcmemory.cpp      |  78 +++++++++++++++++++++++++++++
 src/os2/slider.cpp        |  10 ++++
 src/os2/textctrl.cpp      |   9 ----
 src/os2/window.cpp        |   8 +++
 src/os2/wx23.def          |  18 ++++---
 10 files changed, 175 insertions(+), 104 deletions(-)

diff --git a/include/wx/os2/slider.h b/include/wx/os2/slider.h
index e3f6f87fa5..887177c827 100644
--- a/include/wx/os2/slider.h
+++ b/include/wx/os2/slider.h
@@ -66,6 +66,9 @@ public:
          virtual int  GetValue(void) const ;
          virtual void SetValue(int);
 
+         virtual void DoGetSize( int* pnWidth
+                                ,int* pnHeight
+                               ) const;
                  void GetSize( int* pnX
                               ,int* pnY
                              ) const;
diff --git a/include/wx/os2/textctrl.h b/include/wx/os2/textctrl.h
index b7a701274f..8770ddbda2 100644
--- a/include/wx/os2/textctrl.h
+++ b/include/wx/os2/textctrl.h
@@ -118,7 +118,6 @@ public:
                               ,long lTo
                              );
     virtual void SetEditable(bool bEditable);
-    virtual void SetFocus(void);
     virtual void SetWindowStyleFlag(long lStyle);
 
     //
diff --git a/include/wx/os2/window.h b/include/wx/os2/window.h
index 33ac3ce48b..620b445553 100644
--- a/include/wx/os2/window.h
+++ b/include/wx/os2/window.h
@@ -95,6 +95,7 @@ public:
     virtual bool     Show(bool bShow = TRUE);
     virtual bool     Enable(bool bEnable = TRUE);
     virtual void     SetFocus(void);
+    virtual void     SetFocusFromKbd(void);
     virtual bool     Reparent(wxWindow* pNewParent);
     virtual void     WarpPointer( int x
                                  ,int y
diff --git a/src/os2/bitmap.cpp b/src/os2/bitmap.cpp
index 6a6be7033f..6ea8aa4752 100644
--- a/src/os2/bitmap.cpp
+++ b/src/os2/bitmap.cpp
@@ -548,7 +548,7 @@ bool wxBitmap::CreateFromImage (
     SetWidth(nWidth);
     SetHeight(nBmpHeight);
     if (nDepth == -1)
-        nDepth = 16; // wxDisplayDepth();
+        nDepth = wxDisplayDepth();
     SetDepth(nDepth);
 
 #if wxUSE_PALETTE
@@ -817,6 +817,7 @@ bool wxBitmap::CreateFromImage (
 wxImage wxBitmap::ConvertToImage() const
 {
     wxImage                         vImage;
+    wxDC*                           pDC;
 
     wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
 
@@ -836,12 +837,13 @@ wxImage wxBitmap::ConvertToImage() const
     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;
+    HBITMAP                         hOldBitmap;
+    DEVOPENSTRUC                    vDop  = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
+    SIZEL                           vSizlPage = {0,0};
+    HDC                             hDCMem;
 
     vImage.Create( nWidth
                   ,nHeight
@@ -885,34 +887,54 @@ wxImage wxBitmap::ConvertToImage() const
         return wxNullImage;
     }
 
+    //
+    // May already be selected into a PS
+    //
+    if ((pDC = GetSelectedInto()) != NULL)
+    {
+        hPSMem = pDC->GetHPS();
+    }
+    else
+    {
+        hDCMem = ::DevOpenDC( vHabmain
+                             ,OD_MEMORY
+                             ,"*"
+                             ,5L
+                             ,(PDEVOPENDATA)&vDop
+                             ,NULLHANDLE
+                            );
+        hPSMem = ::GpiCreatePS( vHabmain
+                               ,hDCMem
+                               ,&vSizlPage
+                               ,PU_PELS | GPIA_ASSOC
+                              );
+        hBitmap = (HBITMAP)GetHBITMAP();
+        if ((hOldBitmap = ::GpiSetBitmap(hPSMem, hBitmap)) == HBM_ERROR)
+        {
+            ERRORID                 vError;
+            wxString                sError;
+
+            vError = ::WinGetLastError(vHabmain);
+            sError = wxPMErrorToStr(vError);
+        }
+    }
+
     //
     // Copy data from the device-dependent bitmap to the DIB
     //
-    hDCMem = ::DevOpenDC( vHabmain
-                         ,OD_MEMORY
-                         ,"*"
-                         ,4
-                         ,(PDEVOPENDATA)pszData
-                         ,NULLHANDLE
-                        );
-    hPSMem = ::GpiCreatePS( vHabmain
-                           ,hDCMem
-                           ,&vSizlPage
-                           ,PU_PELS | GPIA_ASSOC | GPIT_MICRO
-                          );
-    hBitmap = ::GpiCreateBitmap( hPSMem
-                                ,&vDIBh
-                                ,0L
-                                ,NULL
-                                ,NULL
-                               );
-    ::GpiSetBitmap(hPSMem, hBitmap);
-    lScans = ::GpiQueryBitmapBits( hPSMem
-                                  ,0L
-                                  ,(LONG)nHeight
-                                  ,(PBYTE)lpBits
-                                  ,&vDIBInfo
-                                 );
+    if ((lScans = ::GpiQueryBitmapBits( hPSMem
+                                       ,0L
+                                       ,(LONG)nHeight
+                                       ,(PBYTE)lpBits
+                                       ,&vDIBInfo
+                                      )) == GPI_ALTERROR)
+    {
+        ERRORID                     vError;
+        wxString                    sError;
+
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+    }
 
     //
     // Copy DIB data into the wxImage object
@@ -933,7 +955,12 @@ wxImage wxBitmap::ConvertToImage() const
         }
         ptbits += nPadding;
     }
-    ::GpiSetBitmap(hPSMem, NULLHANDLE);
+    if ((pDC = GetSelectedInto()) == NULL)
+    {
+        ::GpiSetBitmap(hPSMem, NULLHANDLE);
+        ::GpiDestroyPS(hPSMem);
+        ::DevCloseDC(hDCMem);
+    }
 
     //
     // Similarly, set data according to the possible mask bitmap
@@ -945,13 +972,13 @@ wxImage wxBitmap::ConvertToImage() const
         //
         // Memory DC/PS created, color set, data copied, and memory DC/PS deleted
         //
-        HDC                         hMemDC = ::DevOpenDC( vHabmain
-                                                         ,OD_MEMORY
-                                                         ,"*"
-                                                         ,4
-                                                         ,(PDEVOPENDATA)pszData
-                                                         ,NULLHANDLE
-                                                        );
+        HDC                        hMemDC = ::DevOpenDC( vHabmain
+                                                        ,OD_MEMORY
+                                                        ,"*"
+                                                        ,5L
+                                                        ,(PDEVOPENDATA)&vDop
+                                                        ,NULLHANDLE
+                                                       );
         HPS                         hMemPS = ::GpiCreatePS( vHabmain
                                                            ,hMemDC
                                                            ,&vSizlPage
@@ -1009,8 +1036,6 @@ wxImage wxBitmap::ConvertToImage() const
     //
     // Free allocated resources
     //
-    ::GpiDestroyPS(hPSMem);
-    ::DevCloseDC(hDCMem);
     free(lpBits);
     return vImage;
 } // end of wxBitmap::ConvertToImage
diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp
index 9a58657da1..8bf6f5b520 100644
--- a/src/os2/dc.cpp
+++ b/src/os2/dc.cpp
@@ -1040,54 +1040,6 @@ void wxDC::DoDrawRectangle(
                  ,0L
                  ,0L
                 );
-        //
-        // Debug testing:
-        //
-        if (m_vSelectedBitmap != wxNullBitmap)
-        {
-            BITMAPINFOHEADER2           vHeader;
-            BITMAPINFO2                 vInfo;
-
-            vHeader.cbFix = 16L;
-            if (::GpiQueryBitmapInfoHeader(m_hPS, &vHeader))
-            {
-                int                     nBytesPerLine = vHeader.cBitCount/8;
-                unsigned char*          pucData = NULL;
-                unsigned char*          pucBits;
-                LONG                    lScans = 0L;
-
-                vInfo.cbFix = 16;
-                vInfo.cx              = vHeader.cx;
-                vInfo.cy              = vHeader.cy;
-                vInfo.cPlanes         = vHeader.cPlanes;
-                vInfo.cBitCount       = vHeader.cBitCount;
-                pucData = (unsigned char*)malloc(nBytesPerLine * vHeight);
-                pucBits = pucData;
-                for (int i = 0; i < vHeight; i++)
-                {
-                    if (i <= m_vSelectedBitmap.GetHeight())
-                    {
-                        for (int j = 0; j < vWidth; j++)
-                        {
-                            if (j <= m_vSelectedBitmap.GetWidth())
-                            {
-                                vPoint[0].x = j; vPoint[0].y = i;
-                                lColor = ::GpiQueryPel(m_hPS, &vPoint[0]);
-                                *(pucBits++) = lColor >> 24;
-                                *(pucBits++) = lColor >> 16;
-                                *(pucBits++) = lColor >> 8;
-                            }
-                        }
-                    }
-                }
-                lScans = ::GpiSetBitmapBits( m_hPS
-                                            ,0             // Start at the bottom
-                                            ,(LONG)vHeight // One line per scan
-                                            ,(PBYTE)pucData
-                                            ,&vInfo
-                                           );
-            }
-        }
     }
     CalcBoundingBox(vX, vY);
     CalcBoundingBox(vX2, vY2);
diff --git a/src/os2/dcmemory.cpp b/src/os2/dcmemory.cpp
index 456e93e3d3..435bbf1f3f 100644
--- a/src/os2/dcmemory.cpp
+++ b/src/os2/dcmemory.cpp
@@ -190,4 +190,82 @@ void wxMemoryDC::DoDrawRectangle(
 )
 {
     wxDC::DoDrawRectangle(vX, vY, vWidth, vHeight);
+
+    //
+    // Debug testing:
+    //
+    if (m_vSelectedBitmap.GetHBITMAP() != NULLHANDLE)
+    {
+        BITMAPINFOHEADER2           vHeader;
+        BITMAPINFO2                 vInfo;
+
+        vHeader.cbFix = 16L;
+        if (::GpiQueryBitmapInfoHeader(m_vSelectedBitmap.GetHBITMAP(), &vHeader))
+        {
+            unsigned char*          pucData = NULL;
+            unsigned char*          pucBits;
+            int                     nBytesPerLine = vWidth * 3;
+            LONG                    lScans = 0L;
+            POINTL                  vPoint;
+            LONG                    lColor;
+
+            vInfo.cbFix     = 16;
+            vInfo.cx        = vHeader.cx;
+            vInfo.cy        = vHeader.cy;
+            vInfo.cPlanes   = vHeader.cPlanes;
+            vInfo.cBitCount = 24;
+            pucData = (unsigned char*)malloc(nBytesPerLine * m_vSelectedBitmap.GetHeight());
+            if ((lScans = ::GpiQueryBitmapBits( m_hPS
+                                               ,0L
+                                               ,(LONG)m_vSelectedBitmap.GetHeight()
+                                               ,(PBYTE)pucData
+                                               ,&vInfo
+                                              )) == GPI_ALTERROR)
+            {
+                ERRORID                     vError;
+                wxString                    sError;
+
+                vError = ::WinGetLastError(vHabmain);
+                sError = wxPMErrorToStr(vError);
+            }
+            pucBits = pucData;
+            for (int i = 0; i < m_vSelectedBitmap.GetHeight(); i++)
+            {
+                for (int j = vX; j < m_vSelectedBitmap.GetWidth(); j++)
+                {
+                    if (i >= vY && j >= vX && i < vHeight && j < vWidth)
+                    {
+                        vPoint.x = j; vPoint.y = i;
+                        if (i == vY || j == vX ||
+                            i == m_vSelectedBitmap.GetWidth() -1 ||
+                            j == m_vSelectedBitmap.GetHeight()
+                           )
+                            lColor = m_pen.GetColour().GetPixel();
+                        else
+                            lColor = m_brush.GetColour().GetPixel();
+                        *(pucBits++) = (unsigned char)lColor;
+                        *(pucBits++) = (unsigned char)(lColor >> 8);
+                        *(pucBits++) = (unsigned char)(lColor >> 16);
+                    }
+                    else
+                        pucBits += 3;
+                }
+            }
+            if ((lScans = ::GpiSetBitmapBits( m_hPS
+                                             ,0
+                                             ,(LONG)m_vSelectedBitmap.GetHeight()
+                                             ,(PBYTE)pucData
+                                             ,&vInfo
+                                            )) == GPI_ALTERROR)
+            {
+                ERRORID             vError;
+                wxString            sError;
+
+                vError = ::WinGetLastError(vHabmain);
+                sError = wxPMErrorToStr(vError);
+            }
+            free(pucData);
+        }
+    }
 } // end of wxMemoryDC::DoDrawRectangle
+
diff --git a/src/os2/slider.cpp b/src/os2/slider.cpp
index b190205052..cf5d9798f5 100644
--- a/src/os2/slider.cpp
+++ b/src/os2/slider.cpp
@@ -772,6 +772,16 @@ int wxSlider::GetSelStart() const
     return 0;
 } // end of wxSlider::GetSelStart
 
+void wxSlider::DoGetSize(
+  int*                              pnWidth
+, int*                              pnHeight
+) const
+{
+    GetSize( pnWidth
+            ,pnHeight
+           );
+} // end of wxSlider::DoGetSize
+
 void wxSlider::GetSize(
   int*                              pnWidth
 , int*                              pnHeight
diff --git a/src/os2/textctrl.cpp b/src/os2/textctrl.cpp
index f375a38886..b99d13006c 100644
--- a/src/os2/textctrl.cpp
+++ b/src/os2/textctrl.cpp
@@ -1066,15 +1066,6 @@ void wxTextCtrl::OnChar(
     rEvent.Skip();
 } // end of wxTextCtrl::OnChar
 
-void wxTextCtrl::SetFocus()
-{
-    wxTextCtrlBase::SetFocus();
-    if ( !HasFlag(wxTE_MULTILINE) )
-    {
-        SetSelection(-1, -1);
-    }
-} // end of wxTextCtrl::SetFocus
-
 bool wxTextCtrl::OS2Command(
   WXUINT                            uParam
 , WXWORD                            WXUNUSED(vId)
diff --git a/src/os2/window.cpp b/src/os2/window.cpp
index 0e3bf3063f..dc57ab1911 100644
--- a/src/os2/window.cpp
+++ b/src/os2/window.cpp
@@ -465,6 +465,14 @@ void wxWindowOS2::SetFocus()
         ::WinSetFocus(HWND_DESKTOP, hWnd);
 } // end of wxWindowOS2::SetFocus
 
+void wxWindowOS2::SetFocusFromKbd()
+{
+    //
+    // Nothing else to do under OS/2
+    //
+    wxWindowBase::SetFocusFromKbd();
+} // end of wxWindowOS2::SetFocus
+
 wxWindow* wxWindowBase::FindFocus()
 {
     HWND                            hWnd = ::WinQueryFocus(HWND_DESKTOP);
diff --git a/src/os2/wx23.def b/src/os2/wx23.def
index e183562671..13dfe46c8e 100644
--- a/src/os2/wx23.def
+++ b/src/os2/wx23.def
@@ -4,7 +4,7 @@ DATA MULTIPLE NONSHARED READWRITE LOADONCALL
 CODE LOADONCALL
 
 EXPORTS
-;From library:  F:\DEV\WX2\WXWINDOWS\LIB\wx.lib
+;From library:  H:\dev\wx2\wxwindows\lib\wx.lib
   ;From object file:  dummy.cpp
     ;PUBDEFs (Symbols available from object file):
       wxDummyChar
@@ -1925,7 +1925,7 @@ EXPORTS
       wxEVT_NC_LEFT_DCLICK
       wxEVT_INIT_DIALOG
       wxEVT_COMMAND_SET_FOCUS
-  ;From object file:  F:\DEV\WX2\WXWINDOWS\src\common\extended.c
+  ;From object file:  H:\DEV\WX2\WXWINDOWS\src\common\extended.c
     ;PUBDEFs (Symbols available from object file):
       ConvertToIeeeExtended
       ConvertFromIeeeExtended
@@ -6037,7 +6037,7 @@ EXPORTS
       Read32__17wxTextInputStreamFv
       ;wxTextInputStream::SkipIfEndOfLine(char)
       SkipIfEndOfLine__17wxTextInputStreamFc
-  ;From object file:  F:\DEV\WX2\WXWINDOWS\src\common\unzip.c
+  ;From object file:  H:\DEV\WX2\WXWINDOWS\src\common\unzip.c
     ;PUBDEFs (Symbols available from object file):
       unzReadCurrentFile
       unzGetCurrentFileInfo
@@ -6983,6 +6983,8 @@ EXPORTS
       DeleteRelatedConstraints__12wxWindowBaseFv
       ;wxWindowBase::SetHelpText(const wxString&)
       SetHelpText__12wxWindowBaseFRC8wxString
+      ;wxGetTopLevelParent(wxWindow*)
+      wxGetTopLevelParent__FP8wxWindow
   ;From object file:  ..\common\wxchar.cpp
     ;PUBDEFs (Symbols available from object file):
       ;wxOKlibc()
@@ -10762,6 +10764,8 @@ EXPORTS
       wxConstructorForwxHtmlFilterHTML__Fv
       ;wxHtmlFilterHTML::sm_classwxHtmlFilterHTML
       sm_classwxHtmlFilterHTML__16wxHtmlFilterHTML
+      ;wxPrivate_ReadString(wxString&,wxInputStream*)
+      wxPrivate_ReadString__FR8wxStringP13wxInputStream
       ;wxHtmlFilterPlainText::ReadFile(const wxFSFile&) const
       ReadFile__21wxHtmlFilterPlainTextCFRC8wxFSFile
       ;wxHtmlFilterHTML::ReadFile(const wxFSFile&) const
@@ -14297,8 +14301,6 @@ EXPORTS
       Copy__10wxTextCtrlFv
       ;wxTextCtrl::SetStyle(long,long,const wxTextAttr&)
       SetStyle__10wxTextCtrlFlT1RC10wxTextAttr
-      ;wxTextCtrl::SetFocus()
-      SetFocus__10wxTextCtrlFv
       ;wxTextCtrl::CanRedo() const
       CanRedo__10wxTextCtrlCFv
       ;wxTextCtrl::OS2GetStyle(long,unsigned long*) const
@@ -14799,14 +14801,16 @@ EXPORTS
       wxCharCodeOS2ToWX__Fi
       ;wxWindow::HandleMouseMove(int,int,unsigned int)
       HandleMouseMove__8wxWindowFiT1Ui
-      ;wxWindow::Raise()
-      Raise__8wxWindowFv
+      ;wxWindow::SetFocusFromKbd()
+      SetFocusFromKbd__8wxWindowFv
       ;wxWindowCreationHook::~wxWindowCreationHook()
       __dt__20wxWindowCreationHookFv
       ;wxWindow::Update()
       Update__8wxWindowFv
       ;wxWindow::UnsubclassWin()
       UnsubclassWin__8wxWindowFv
+      ;wxWindow::Raise()
+      Raise__8wxWindowFv
       ;wxWindow::Lower()
       Lower__8wxWindowFv
       ;wxWindow::HandleMaximize()
-- 
2.50.0

