X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0e320a79f187558effb04d92020b470372bbe456..da6f998486f1070e205f2e0a54f22a1b67cb32a4:/src/os2/combobox.cpp diff --git a/src/os2/combobox.cpp b/src/os2/combobox.cpp index 0be841bad4..9cf412cb15 100644 --- a/src/os2/combobox.cpp +++ b/src/os2/combobox.cpp @@ -1,165 +1,281 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: combobox.cpp +// Name: src/os2/combobox.cpp // Purpose: wxComboBox class -// Author: AUTHOR +// Author: David Webster // Modified by: -// Created: ??/??/98 -// RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Created: 10/13/99 +// Copyright: (c) David Webster +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "combobox.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_COMBOBOX #include "wx/combobox.h" -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) +#ifndef WX_PRECOMP + #include "wx/settings.h" #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) +#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; + +bool wxComboBox::OS2Command( WXUINT uParam, WXWORD WXUNUSED(wId) ) { - SetName(name); - SetValidator(validator); - m_noStrings = n; - m_windowStyle = style; + long lSel = GetSelection(); + wxString sValue; - if (parent) parent->AddChild(this); + switch (uParam) + { + case CBN_LBSELECT: + if (lSel > -1) + { + wxCommandEvent vEvent( wxEVT_COMBOBOX, GetId() ); - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; + vEvent.SetInt(lSel); + vEvent.SetEventObject(this); + vEvent.SetString(GetStringSelection()); - // TODO: create combobox control + ProcessCommand(vEvent); + } + break; - return TRUE; -} + case CBN_EFCHANGE: + { + wxCommandEvent vEvent( wxEVT_TEXT, GetId() ); -wxString wxComboBox::GetValue() const -{ - // TODO - return wxString(""); -} + if (lSel == -1L) + sValue = GetValue(); + else + sValue = GetStringSelection(); + vEvent.SetString(sValue); + 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 -void wxComboBox::SetValue(const wxString& value) +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 +) { - // TODO -} + wxCArrayString chs(asChoices); -// Clipboard operations -void wxComboBox::Copy() -{ - // TODO + return Create(pParent, vId, rsValue, rPos, rSize, chs.GetCount(), + chs.GetStrings(), lStyle, rValidator, rsName); } -void wxComboBox::Cut() +bool wxComboBox::Create( + wxWindow* pParent +, wxWindowID vId +, const wxString& rsValue +, const wxPoint& rPos +, const wxSize& rSize +, int n +, const wxString asChoices[] +, long lStyle +, const wxValidator& rValidator +, const wxString& rsName +) { - // TODO -} + m_isShown = false; -void wxComboBox::Paste() -{ - // TODO -} + if (!CreateControl( pParent + ,vId + ,rPos + ,rSize + ,lStyle + ,rValidator + ,rsName + )) + return false; -void wxComboBox::SetEditable(bool editable) -{ - // TODO -} + // + // Get the right style + // + long lSstyle = 0L; -void wxComboBox::SetInsertionPoint(long pos) -{ - // TODO -} + lSstyle = WS_TABSTOP | + WS_VISIBLE; -void wxComboBox::SetInsertionPointEnd() -{ - // TODO -} + // 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) + lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control + else + lSstyle |= CBS_DROPDOWN; -long wxComboBox::GetInsertionPoint() const -{ - // TODO - return 0; -} -long wxComboBox::GetLastPosition() const -{ - // TODO - return 0; -} + if (!OS2CreateControl( wxT("COMBOBOX") + ,lSstyle + )) + return false; -void wxComboBox::Replace(long from, long to, const wxString& value) -{ - // TODO -} + // + // A choice/combobox normally has a white background (or other, depending + // on global settings) rather than inheriting the parent's background colour. + // + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); -void wxComboBox::Remove(long from, long to) -{ - // TODO -} + for (int i = 0; i < n; i++) + { + Append(asChoices[i]); + } -void wxComboBox::SetSelection(long from, long to) -{ - // TODO -} + SetSize( rPos.x + ,rPos.y + ,rSize.x + ,rSize.y + ); + + // 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); + } + gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd() + ,(PFNWP)wxComboEditWndProc + ); + ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this); + Show(true); + return true; +} // end of wxComboBox::Create -void wxComboBox::Append(const wxString& item) +wxString wxComboBox::GetValue() const { - // TODO + return HasFlag(wxCB_READONLY) ? GetStringSelection() + : wxTextEntry::GetValue(); } -void wxComboBox::Delete(int n) +void wxComboBox::SetValue(const wxString& value) { - // TODO + if ( HasFlag(wxCB_READONLY) ) + SetStringSelection(value); + else + wxTextEntry::SetValue(value); } void wxComboBox::Clear() { - // TODO + wxChoice::Clear(); + if ( !HasFlag(wxCB_READONLY) ) + wxTextEntry::Clear(); } -int wxComboBox::GetSelection() const +bool wxComboBox::IsEditable() const { - // TODO - return -1; + return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable(); } -void wxComboBox::SetSelection(int n) +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( wParam + ,lParam + ,true /* isASCII */ + )); -int wxComboBox::FindString(const wxString& s) const -{ - // TODO - return -1; -} + case KC_PREVDOWN: + return (HandleKeyDown( wParam + ,lParam + )); -wxString wxComboBox::GetString(int n) const -{ - // TODO - return wxString(""); -} + case KC_KEYUP: + return (HandleKeyUp( wParam + ,lParam + )); + } + break; -wxString wxComboBox::GetStringSelection() const -{ - // TODO - return wxString(""); -} + case WM_SETFOCUS: + if (SHORT1FROMMP((MPARAM)lParam) == TRUE) + return(HandleSetFocus((WXHWND)(HWND)wParam)); + else + return(HandleKillFocus((WXHWND)(HWND)wParam)); + } + return false; +} // end of wxComboBox::ProcessEditMsg -bool wxComboBox::SetStringSelection(const wxString& sel) +MRESULT EXPENTRY wxComboEditWndProc( + HWND hWnd +, UINT uMessage +, MPARAM wParam +, MPARAM lParam +) { - // TODO - return FALSE; -} + switch (uMessage) + { + // + // Forward some messages to the combobox + // + case WM_SETFOCUS: + case WM_CHAR: + { + wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd + ,QWL_USER + ); + + 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