]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/combobox.cpp
Added wxDynamicSashWindow to wxPython, plus other odds and ends.
[wxWidgets.git] / src / os2 / combobox.cpp
index 0be841bad4dabe1a3db99195f50a26b7b2419441..e062a2f24aa7b607e630b5bd17fefd793285dc38 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
 // Name:        combobox.cpp
 // Purpose:     wxComboBox class
-// Author:      AUTHOR
+// Author:      David Webster
 // Modified by:
-// Created:     ??/??/98
+// Created:     10/13/99
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
-// Licence:    wxWindows licence
+// Copyright:   (c) David Webster
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "combobox.h"
+#include "wx/combobox.h"
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+#include "wx/setup.h"
 #endif
 
+#if wxUSE_COMBOBOX
+
 #include "wx/combobox.h"
+#include "wx/clipbrd.h"
+#include "wx/os2/private.h"
+
+#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE    (1)
+
+MRESULT EXPENTRY wxComboEditWndProc( HWND   hWnd
+                                    ,UINT   uMessage
+                                    ,MPARAM wParam
+                                    ,MPARAM lParam
+                                   );
+//
+// The pointer to standard wnd proc
+//
+static WXFARPROC gfnWndprocEdit     = (WXFARPROC)NULL;
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
-#endif
 
-bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
-           const wxString& value,
-           const wxPoint& pos,
-           const wxSize& size,
-                  int n, const wxString choices[],
-                  long style,
-           const wxValidator& validator,
-           const wxString& name)
+bool wxComboBox::OS2Command(
+  WXUINT                            uParam
+, WXWORD                            WXUNUSED(wId)
+)
 {
-    SetName(name);
-    SetValidator(validator);
-    m_noStrings = n;
-    m_windowStyle = style;
+    long                            lSel = -1L;
+    wxString                        sValue;
 
-    if (parent) parent->AddChild(this);
+    switch (uParam)
+    {
+        case LN_SELECT:
+            if (GetSelection() > -1)
+            {
+                wxCommandEvent      vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
+                                           ,GetId()
+                                          );
+
+                vEvent.SetInt(GetSelection());
+                vEvent.SetEventObject(this);
+                vEvent.SetString((char*)GetStringSelection().c_str());
+                ProcessCommand(vEvent);
+            }
+            break;
+
+        case EN_CHANGE:
+            {
+                wxCommandEvent      vEvent( wxEVT_COMMAND_TEXT_UPDATED
+                                           ,GetId()
+                                          );
+
+                if (lSel == -1L)
+                    sValue = GetValue();
+                else
+                    SetValue(sValue);
+                vEvent.SetString((char*)GetValue().c_str());
+                vEvent.SetEventObject(this);
+                ProcessCommand(vEvent);
+            }
+            break;
+    }
+    //
+    // There is no return value for the CBN_ notifications, so always return
+    // FALSE from here to pass the message to DefWindowProc()
+    //
+    return FALSE;
+} // end of wxComboBox::OS2Command
+
+bool wxComboBox::Create(
+  wxWindow*                         pParent
+, wxWindowID                        vId
+, const wxString&                   rsValue
+, const wxPoint&                    rPos
+, const wxSize&                     rSize
+, int                               n
+, const wxString                    asChoices[]
+, long                              lStyle
+#if wxUSE_VALIDATORS
+, const wxValidator&                rValidator
+#endif
+, const wxString&                   rsName
+)
+{
 
-    if ( id == -1 )
-       m_windowId = (int)NewControlId();
+    if (!OS2CreateControl( pParent
+                       ,vId
+                       ,rPos
+                       ,rSize
+                       ,lStyle
+#if wxUSE_VALIDATORS
+                       ,rValidator
+#endif
+                       ,rsName
+                      ))
+        return FALSE;
+
+    //
+    // Get the right style
+    //
+    long                            lSstyle = 0L;
+
+    lSstyle = WS_TABSTOP   |
+              WS_VISIBLE;
+
+    if (lStyle & wxCLIP_SIBLINGS )
+        lSstyle |= WS_CLIPSIBLINGS;
+    if (lStyle & wxCB_READONLY)
+        lSstyle |= CBS_DROPDOWNLIST;
+    else if (lStyle & wxCB_SIMPLE)
+        lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control
     else
-       m_windowId = id;
+        lSstyle |= CBS_DROPDOWN;
+
+
+    if (!OS2CreateControl( "COMBOBOX"
+                          ,lSstyle
+                         ))
+        return FALSE;
+
+    //
+    // A choice/combobox normally has a white background (or other, depending
+    // on global settings) rather than inheriting the parent's background colour.
+    //
+    SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
 
-    // TODO: create combobox control
+    SetFont(pParent->GetFont());
 
+    int                             i;
+
+    for (i = 0; i < n; i++)
+    {
+        Append(asChoices[i]);
+    }
+
+    SetSize( rPos.x
+            ,rPos.y
+            ,rSize.x
+            ,rSize.y
+           );
+    if (!rsValue.IsEmpty())
+    {
+        SetValue(rsValue);
+    }
+    gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd()
+                                                    ,(PFNWP)wxComboEditWndProc
+                                                   );
     return TRUE;
-}
+} // end of wxComboBox::Create
 
-wxString wxComboBox::GetValue() const
+void wxComboBox::SetValue(
+  const wxString&                   rsValue
+)
 {
-    // TODO
-    return wxString("");
-}
+    //
+    // If newlines are denoted by just 10, must stick 13 in front.
+    //
+    int                             nSingletons = 0;
+    int                             nLen = rsValue.Length();
+    int                             i;
 
-void wxComboBox::SetValue(const wxString& value)
-{
-    // TODO
-}
+    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()
 {
-    // TODO
-}
+    HWND                            hWnd = GetHwnd();
+
+    ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
+} // end of wxComboBox::Copy
 
 void wxComboBox::Cut()
 {
-    // TODO
-}
+    HWND                            hWnd = GetHwnd();
+
+    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
+} // end of wxComboBox::Cut
 
 void wxComboBox::Paste()
 {
-    // TODO
-}
+    HWND                            hWnd = GetHwnd();
+
+    ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
+} // end of wxComboBox::Paste
 
-void wxComboBox::SetEditable(bool editable)
+void wxComboBox::SetEditable(
+  bool                              bEditable
+)
 {
-    // TODO
-}
+    HWND                            hWnd = GetHwnd();
 
-void wxComboBox::SetInsertionPoint(long pos)
+    ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
+} // end of wxComboBox::SetEditable
+
+void wxComboBox::SetInsertionPoint(
+  long                              lPos
+)
 {
-    // TODO
-}
+    HWND                            hWnd = GetHwnd();
+
+    ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
+} // end of wxComboBox::SetInsertionPoint
 
 void wxComboBox::SetInsertionPointEnd()
 {
-    // TODO
-}
+    long                            lPos = GetLastPosition();
+
+    SetInsertionPoint(lPos);
+} // end of wxComboBox::SetInsertionPointEnd
 
 long wxComboBox::GetInsertionPoint() const
 {
-    // TODO
-    return 0;
-}
+    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
 {
-    // TODO
-    return 0;
-}
+    HWND                            hEditWnd = GetHwnd();
+    long                            lLineLength = 0L;
+    WNDPARAMS                       vParams;
 
-void wxComboBox::Replace(long from, long to, const wxString& value)
-{
-    // TODO
-}
+    //
+    // Get number of characters in the last (only) line. We'll add this to the character
+    // index for the last line, 1st position.
+    //
 
-void wxComboBox::Remove(long from, long to)
-{
-    // TODO
-}
 
-void wxComboBox::SetSelection(long from, long to)
-{
-    // TODO
-}
+    vParams.fsStatus = WPM_CCHTEXT;
+    if (::WinSendMsg( GetHwnd()
+                     ,WM_QUERYWINDOWPARAMS
+                     ,&vParams
+                     ,0
+                    ))
+    {
+        lLineLength = (long)vParams.cchText;
+    }
+    else
+        lLineLength = 0L;
+    return lLineLength;
+} // end of wxComboBox::GetLastPosition
 
-void wxComboBox::Append(const wxString& item)
+void wxComboBox::Replace(
+  long                              lFrom
+, long                              lTo
+, const wxString&                   rsValue
+)
 {
-    // TODO
-}
+#if wxUSE_CLIPBOARD
+    HWND                            hWnd = GetHwnd();
+    long                            lFromChar = lFrom;
+    long                            lToChar = lTo;
 
-void wxComboBox::Delete(int n)
-{
-    // TODO
-}
+    //
+    // Set selection and remove it
+    //
+    ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
+    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
 
-void wxComboBox::Clear()
-{
-    // TODO
-}
+    //
+    // Now replace with 'value', by pasting.
+    //
+    wxSetClipboardData( wxDF_TEXT
+                       ,(wxObject *)rsValue.c_str()
+                       ,0
+                       ,0
+                      );
 
-int wxComboBox::GetSelection() const
-{
-    // TODO
-    return -1;
-}
+    //
+    // Paste into edit control
+    //
+    ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
+#endif
+} // end of wxComboBox::Replace
 
-void wxComboBox::SetSelection(int n)
+void wxComboBox::Remove(
+  long                              lFrom
+, long                              lTo
+)
 {
-    // TODO
-}
+#if wxUSE_CLIPBOARD
+    HWND                            hWnd = GetHwnd();
+    long                            lFromChar = lFrom;
+    long                            lToChar = lTo;
 
-int wxComboBox::FindString(const wxString& s) const
-{
-    // TODO
-    return -1;
-}
+    ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
+    ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
+#endif
+} // end of wxComboBox::Remove
 
-wxString wxComboBox::GetString(int n) const
+void wxComboBox::SetSelection(
+  long                              lFrom
+, long                              lTo
+)
 {
-    // TODO
-    return wxString("");
-}
+    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;
+    }
 
-wxString wxComboBox::GetStringSelection() const
+    ::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
+)
 {
-    // TODO
-    return wxString("");
-}
+    wxControl::DoSetSize( nX
+                         ,nY
+                         ,nWidth
+                         ,nHeight
+                         ,nSizeFlags
+                        );
+} // end of wxComboBox::DoSetSize
 
-bool wxComboBox::SetStringSelection(const wxString& sel)
+bool wxComboBox::ProcessEditMsg(
+  WXUINT                            uMsg
+, WXWPARAM                          wParam
+, WXLPARAM                          lParam)
 {
-    // TODO
+    SHORT                           vFlag;
+    switch (uMsg)
+    {
+        case WM_CHAR:
+            vFlag = SHORT1FROMMP(wParam);
+            switch(vFlag)
+            {
+                case KC_CHAR:
+                    return (HandleChar( SHORT1FROMMP(wParam)
+                                       ,lParam
+                                       ,TRUE /* isASCII */
+                                      ));
+
+                case KC_PREVDOWN:
+                    return (HandleKeyDown( SHORT1FROMMP(wParam)
+                                          ,lParam
+                                         ));
+
+                case KC_KEYUP:
+                    return (HandleKeyUp( SHORT1FROMMP(wParam)
+                                        ,lParam
+                                       ));
+            }
+            break;
+    }
     return FALSE;
-}
+} // end of WinGuiBase_CComboBox::ProcessEditMsg
+
+MRESULT EXPENTRY wxComboEditWndProc(
+  HWND                              hWnd
+, UINT                              uMessage
+, MPARAM                            wParam
+, 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_CHAR:
+            {
+                wxComboBox*         pCombo = wxDynamicCast( pWin
+                                                           ,wxComboBox
+                                                          );
+
+                if (pCombo->ProcessEditMsg( uMessage
+                                           ,wParam
+                                           ,lParam
+                                          ))
+                    return ((MRESULT)0);
+            }
+            break;
+
+        //
+        // TODO: Deal with tooltips here
+        //
+    }
+    return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam));
+} // end of wxComboEditWndProc
+
+#endif
+ // wxUSE_COMBOBOX
+