]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/combobox.cpp
exposing wxOSXGetViewFromResponder
[wxWidgets.git] / src / os2 / combobox.cpp
index fc4697b255af247b86d2a9fe607e18ade0997afd..2e3d4f6371dcf84aada86ada6b489385ce381b1f 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        combobox.cpp
+// Name:        src/os2/combobox.cpp
 // Purpose:     wxComboBox class
 // Author:      David Webster
 // Modified by:
@@ -9,19 +9,17 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#include "wx/combobox.h"
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#if wxUSE_COMBOBOX
+
+#include "wx/combobox.h"
+
 #ifndef WX_PRECOMP
-    #include "wx/setup.h"
     #include "wx/settings.h"
 #endif
 
-#if wxUSE_COMBOBOX
-
-#include "wx/combobox.h"
 #include "wx/clipbrd.h"
 #include "wx/os2/private.h"
 
@@ -37,43 +35,35 @@ MRESULT EXPENTRY wxComboEditWndProc( HWND   hWnd
 //
 static WXFARPROC gfnWndprocEdit     = (WXFARPROC)NULL;
 
-IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
-
-bool wxComboBox::OS2Command(
-  WXUINT                            uParam
-, WXWORD                            WXUNUSED(wId)
-)
+bool wxComboBox::OS2Command( WXUINT uParam, WXWORD WXUNUSED(wId) )
 {
-    long                            lSel = -1L;
-    wxString                        sValue;
+    long lSel = GetSelection();
+    wxString sValue;
 
     switch (uParam)
     {
-        case LN_SELECT:
-            if (GetSelection() > -1)
+        case CBN_LBSELECT:
+            if (lSel > -1)
             {
-                wxCommandEvent      vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
-                                           ,GetId()
-                                          );
+                wxCommandEvent vEvent( wxEVT_COMBOBOX, GetId() );
 
-                vEvent.SetInt(GetSelection());
+                vEvent.SetInt(lSel);
                 vEvent.SetEventObject(this);
-                vEvent.SetString((char*)GetStringSelection().c_str());
+                vEvent.SetString(GetStringSelection());
+
                 ProcessCommand(vEvent);
             }
             break;
 
-        case EN_CHANGE:
+        case CBN_EFCHANGE:
             {
-                wxCommandEvent      vEvent( wxEVT_COMMAND_TEXT_UPDATED
-                                           ,GetId()
-                                          );
+                wxCommandEvent vEvent( wxEVT_TEXT, GetId() );
 
                 if (lSel == -1L)
                     sValue = GetValue();
                 else
-                    SetValue(sValue);
-                vEvent.SetString((char*)GetValue().c_str());
+                    sValue = GetStringSelection();
+                vEvent.SetString(sValue);
                 vEvent.SetEventObject(this);
                 ProcessCommand(vEvent);
             }
@@ -81,11 +71,29 @@ bool wxComboBox::OS2Command(
     }
     //
     // There is no return value for the CBN_ notifications, so always return
-    // FALSE from here to pass the message to DefWindowProc()
+    // false from here to pass the message to DefWindowProc()
     //
-    return FALSE;
+    return false;
 } // end of wxComboBox::OS2Command
 
+bool wxComboBox::Create(
+  wxWindow*                         pParent
+, wxWindowID                        vId
+, const wxString&                   rsValue
+, const wxPoint&                    rPos
+, const wxSize&                     rSize
+, const wxArrayString&              asChoices
+, long                              lStyle
+, const wxValidator&                rValidator
+, const wxString&                   rsName
+)
+{
+    wxCArrayString chs(asChoices);
+
+    return Create(pParent, vId, rsValue, rPos, rSize, chs.GetCount(),
+                  chs.GetStrings(), lStyle, rValidator, rsName);
+}
+
 bool wxComboBox::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
@@ -95,24 +103,21 @@ bool wxComboBox::Create(
 , int                               n
 , const wxString                    asChoices[]
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rValidator
-#endif
 , const wxString&                   rsName
 )
 {
+    m_isShown = false;
 
-    if (!OS2CreateControl( pParent
+    if (!CreateControl( pParent
                        ,vId
                        ,rPos
                        ,rSize
                        ,lStyle
-#if wxUSE_VALIDATORS
                        ,rValidator
-#endif
                        ,rsName
                       ))
-        return FALSE;
+        return false;
 
     //
     // Get the right style
@@ -122,8 +127,9 @@ bool wxComboBox::Create(
     lSstyle = WS_TABSTOP   |
               WS_VISIBLE;
 
-    if (lStyle & wxCLIP_SIBLINGS )
-        lSstyle |= WS_CLIPSIBLINGS;
+    // clipping siblings does not yet work
+    // if (lStyle & wxCLIP_SIBLINGS )
+    //     lSstyle |= WS_CLIPSIBLINGS;
     if (lStyle & wxCB_READONLY)
         lSstyle |= CBS_DROPDOWNLIST;
     else if (lStyle & wxCB_SIMPLE)
@@ -132,10 +138,10 @@ bool wxComboBox::Create(
         lSstyle |= CBS_DROPDOWN;
 
 
-    if (!OS2CreateControl( "COMBOBOX"
+    if (!OS2CreateControl( wxT("COMBOBOX")
                           ,lSstyle
                          ))
-        return FALSE;
+        return false;
 
     //
     // A choice/combobox normally has a white background (or other, depending
@@ -143,11 +149,7 @@ bool wxComboBox::Create(
     //
     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
 
-    SetFont(*wxSMALL_FONT);
-
-    int                             i;
-
-    for (i = 0; i < n; i++)
+    for (int i = 0; i < n; i++)
     {
         Append(asChoices[i]);
     }
@@ -157,7 +159,15 @@ bool wxComboBox::Create(
             ,rSize.x
             ,rSize.y
            );
-    if (!rsValue.IsEmpty())
+
+    // Set height to use with sizers i.e. without the dropdown listbox
+    wxFont vFont = GetFont();
+    int nEditHeight;
+    wxGetCharSize( GetHWND(), NULL, &nEditHeight, &vFont );
+    nEditHeight = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nEditHeight);
+    SetInitialSize(wxSize(-1,nEditHeight+4));   // +2x2 for the border
+
+    if (!rsValue.empty())
     {
         SetValue(rsValue);
     }
@@ -165,225 +175,35 @@ bool wxComboBox::Create(
                                                     ,(PFNWP)wxComboEditWndProc
                                                    );
     ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
-    return TRUE;
+    Show(true);
+    return true;
 } // end of wxComboBox::Create
 
-void wxComboBox::SetValue(
-  const wxString&                   rsValue
-)
-{
-    //
-    // If newlines are denoted by just 10, must stick 13 in front.
-    //
-    int                             nSingletons = 0;
-    int                             nLen = rsValue.Length();
-    int                             i;
-
-    for (i = 0; i < nLen; i ++)
-    {
-        if ((i > 0) && (rsValue[i] == 10) && (rsValue[i - 1] != 13))
-            nSingletons ++;
-    }
-    if (nSingletons > 0)
-    {
-        wxChar*                     zTmp = new wxChar[nLen + nSingletons + 1];
-        int                         j = 0;
-
-        for (i = 0; i < nLen; i ++)
-        {
-            if ((i > 0) && (rsValue[i] == 10) && (rsValue[i - 1] != 13))
-            {
-                zTmp[j] = 13;
-                j++;
-            }
-            zTmp[j] = rsValue[i];
-            j++;
-        }
-        zTmp[j] = 0;
-        ::WinSetWindowText(GetHwnd(), zTmp);
-        delete[] zTmp;
-    }
-    else
-        ::WinSetWindowText(GetHwnd(), rsValue.c_str());
-} // end of wxComboBox::SetValue
-
-//
-// Clipboard operations
-//
-void wxComboBox::Copy()
-{
-    HWND                            hWnd = GetHwnd();
-
-    ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
-} // end of wxComboBox::Copy
-
-void wxComboBox::Cut()
-{
-    HWND                            hWnd = GetHwnd();
-
-    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
-} // end of wxComboBox::Cut
-
-void wxComboBox::Paste()
-{
-    HWND                            hWnd = GetHwnd();
-
-    ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
-} // end of wxComboBox::Paste
-
-void wxComboBox::SetEditable(
-  bool                              bEditable
-)
-{
-    HWND                            hWnd = GetHwnd();
-
-    ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
-} // end of wxComboBox::SetEditable
-
-void wxComboBox::SetInsertionPoint(
-  long                              lPos
-)
-{
-    HWND                            hWnd = GetHwnd();
-
-    ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
-} // end of wxComboBox::SetInsertionPoint
-
-void wxComboBox::SetInsertionPointEnd()
+wxString wxComboBox::GetValue() const
 {
-    long                            lPos = GetLastPosition();
+    return HasFlag(wxCB_READONLY) ? GetStringSelection()
+                                  : wxTextEntry::GetValue();
+}
 
-    SetInsertionPoint(lPos);
-} // end of wxComboBox::SetInsertionPointEnd
-
-long wxComboBox::GetInsertionPoint() const
-{
-    long                            lPos = LONGFROMMR(::WinSendMsg( GetHwnd()
-                                                                   ,LM_QUERYSELECTION
-                                                                   ,(MPARAM)0
-                                                                   ,(MPARAM)0
-                                                                  ));
-   if (lPos == LIT_NONE)
-        return wxNOT_FOUND;
-   return lPos;
-} // end of wxComboBox::GetInsertionPoint
-
-long wxComboBox::GetLastPosition() const
+void wxComboBox::SetValue(const wxString& value)
 {
-    HWND                            hEditWnd = GetHwnd();
-    long                            lLineLength = 0L;
-    WNDPARAMS                       vParams;
-
-    //
-    // Get number of characters in the last (only) line. We'll add this to the character
-    // index for the last line, 1st position.
-    //
-
-
-    vParams.fsStatus = WPM_CCHTEXT;
-    if (::WinSendMsg( GetHwnd()
-                     ,WM_QUERYWINDOWPARAMS
-                     ,&vParams
-                     ,0
-                    ))
-    {
-        lLineLength = (long)vParams.cchText;
-    }
+    if ( HasFlag(wxCB_READONLY) )
+        SetStringSelection(value);
     else
-        lLineLength = 0L;
-    return lLineLength;
-} // end of wxComboBox::GetLastPosition
+        wxTextEntry::SetValue(value);
+}
 
-void wxComboBox::Replace(
-  long                              lFrom
-, long                              lTo
-, const wxString&                   rsValue
-)
+void wxComboBox::Clear()
 {
-#if wxUSE_CLIPBOARD
-    HWND                            hWnd = GetHwnd();
-    long                            lFromChar = lFrom;
-    long                            lToChar = lTo;
+    wxChoice::Clear();
+    if ( !HasFlag(wxCB_READONLY) )
+        wxTextEntry::Clear();
+}
 
-    //
-    // Set selection and remove it
-    //
-    ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
-    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
-
-    //
-    // Now replace with 'value', by pasting.
-    //
-    wxSetClipboardData( wxDF_TEXT
-                       ,(wxObject *)rsValue.c_str()
-                       ,0
-                       ,0
-                      );
-
-    //
-    // Paste into edit control
-    //
-    ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
-#endif
-} // end of wxComboBox::Replace
-
-void wxComboBox::Remove(
-  long                              lFrom
-, long                              lTo
-)
+bool wxComboBox::IsEditable() const
 {
-#if wxUSE_CLIPBOARD
-    HWND                            hWnd = GetHwnd();
-    long                            lFromChar = lFrom;
-    long                            lToChar = lTo;
-
-    ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
-    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
-#endif
-} // end of wxComboBox::Remove
-
-void wxComboBox::SetSelection(
-  long                              lFrom
-, long                              lTo
-)
-{
-    HWND                            hWnd = GetHwnd();
-    long                            lFromChar = lFrom;
-    long                            lToChar = lTo;
-
-    //
-    // If from and to are both -1, it means
-    // (in wxWindows) that all text should be selected.
-    // This translates into Windows convention
-    //
-    if ((lFrom == -1L) && (lTo == -1L))
-    {
-        lFromChar = 0;
-        lToChar = -1;
-    }
-
-    ::WinSendMsg( hWnd
-                 ,EM_SETSEL
-                 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
-                 ,(MPARAM)0
-                );
-} // end of wxComboBox::SetSelection
-
-void wxComboBox::DoSetSize(
-  int                               nX
-, int                               nY
-, int                               nWidth
-, int                               nHeight
-, int                               nSizeFlags
-)
-{
-    wxControl::DoSetSize( nX
-                         ,nY
-                         ,nWidth
-                         ,nHeight
-                         ,nSizeFlags
-                        );
-} // end of wxComboBox::DoSetSize
+    return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
+}
 
 bool wxComboBox::ProcessEditMsg(
   WXUINT                            uMsg
@@ -398,25 +218,31 @@ bool wxComboBox::ProcessEditMsg(
             switch(vFlag)
             {
                 case KC_CHAR:
-                    return (HandleChar( SHORT1FROMMP(wParam)
+                    return (HandleChar( wParam
                                        ,lParam
-                                       ,TRUE /* isASCII */
+                                       ,true /* isASCII */
                                       ));
 
                 case KC_PREVDOWN:
-                    return (HandleKeyDown( SHORT1FROMMP(wParam)
+                    return (HandleKeyDown( wParam
                                           ,lParam
                                          ));
 
                 case KC_KEYUP:
-                    return (HandleKeyUp( SHORT1FROMMP(wParam)
+                    return (HandleKeyUp( wParam
                                         ,lParam
                                        ));
             }
             break;
+
+        case WM_SETFOCUS:
+            if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
+                return(HandleSetFocus((WXHWND)(HWND)wParam));
+            else
+                return(HandleKillFocus((WXHWND)(HWND)wParam));
     }
-    return FALSE;
-} // end of WinGuiBase_CComboBox::ProcessEditMsg
+    return false;
+} // end of wxComboBox::ProcessEditMsg
 
 MRESULT EXPENTRY wxComboEditWndProc(
   HWND                              hWnd
@@ -425,21 +251,17 @@ MRESULT EXPENTRY wxComboEditWndProc(
 , MPARAM                            lParam
 )
 {
-    HWND                            hWndCombo;
-    wxWindow*                       pWin = NULL;
-
-    hWndCombo = ::WinQueryWindow(hWnd, QW_PARENT);
-    pWin = (wxWindow*)wxFindWinFromHandle((WXHWND)hWndCombo);
     switch (uMessage)
     {
         //
         // Forward some messages to the combobox
         //
+        case WM_SETFOCUS:
         case WM_CHAR:
             {
-                wxComboBox*         pCombo = wxDynamicCast( pWin
-                                                           ,wxComboBox
-                                                          );
+                wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd
+                                                                         ,QWL_USER
+                                                                        );
 
                 if (pCombo->ProcessEditMsg( uMessage
                                            ,wParam
@@ -458,4 +280,3 @@ MRESULT EXPENTRY wxComboEditWndProc(
 
 #endif
  // wxUSE_COMBOBOX
-