1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxComboBox class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/combobox.h" 
  14 // For compilers that support precompilation, includes "wx.h". 
  15 #include "wx/wxprec.h" 
  19     #include "wx/settings.h" 
  24 #include "wx/combobox.h" 
  25 #include "wx/clipbrd.h" 
  26 #include "wx/os2/private.h" 
  28 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE    (1) 
  30 MRESULT EXPENTRY 
wxComboEditWndProc( HWND   hWnd
 
  36 // The pointer to standard wnd proc 
  38 static WXFARPROC gfnWndprocEdit     
= (WXFARPROC
)NULL
; 
  40 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
) 
  42 bool wxComboBox::OS2Command( 
  44 , WXWORD                            
WXUNUSED(wId
) 
  53             if (GetSelection() > -1) 
  55                 wxCommandEvent      
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
 
  59                 vEvent
.SetInt(GetSelection()); 
  60                 vEvent
.SetEventObject(this); 
  61                 vEvent
.SetString((char*)GetStringSelection().c_str()); 
  62                 ProcessCommand(vEvent
); 
  68                 wxCommandEvent      
vEvent( wxEVT_COMMAND_TEXT_UPDATED
 
  76                 vEvent
.SetString((char*)GetValue().c_str()); 
  77                 vEvent
.SetEventObject(this); 
  78                 ProcessCommand(vEvent
); 
  83     // There is no return value for the CBN_ notifications, so always return 
  84     // FALSE from here to pass the message to DefWindowProc() 
  87 } // end of wxComboBox::OS2Command 
  89 bool wxComboBox::Create( 
  92 , const wxString
&                   rsValue
 
  95 , const wxArrayString
&              asChoices
 
  97 , const wxValidator
&                rValidator
 
  98 , const wxString
&                   rsName
 
 101     wxCArrayString 
chs(asChoices
); 
 103     return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(), 
 104                   chs
.GetStrings(), lStyle
, rValidator
, rsName
); 
 107 bool wxComboBox::Create( 
 110 , const wxString
&                   rsValue
 
 111 , const wxPoint
&                    rPos
 
 112 , const wxSize
&                     rSize
 
 114 , const wxString                    asChoices
[] 
 116 , const wxValidator
&                rValidator
 
 117 , const wxString
&                   rsName
 
 122     if (!CreateControl( pParent
 
 133     // Get the right style 
 137     lSstyle 
= WS_TABSTOP   
| 
 140     if (lStyle 
& wxCLIP_SIBLINGS 
) 
 141         lSstyle 
|= WS_CLIPSIBLINGS
; 
 142     if (lStyle 
& wxCB_READONLY
) 
 143         lSstyle 
|= CBS_DROPDOWNLIST
; 
 144     else if (lStyle 
& wxCB_SIMPLE
) 
 145         lSstyle 
|= CBS_SIMPLE
; // A list (shown always) and edit control 
 147         lSstyle 
|= CBS_DROPDOWN
; 
 150     if (!OS2CreateControl( "COMBOBOX" 
 156     // A choice/combobox normally has a white background (or other, depending 
 157     // on global settings) rather than inheriting the parent's background colour. 
 159     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)); 
 161     SetFont(*wxSMALL_FONT
); 
 164     for (i 
= 0; i 
< n
; i
++) 
 166         Append(asChoices
[i
]); 
 174     if (!rsValue
.IsEmpty()) 
 178     gfnWndprocEdit 
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd() 
 179                                                     ,(PFNWP
)wxComboEditWndProc
 
 181     ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this); 
 184 } // end of wxComboBox::Create 
 186 void wxComboBox::SetValue( 
 187   const wxString
&                   rsValue
 
 190     if ( HasFlag(wxCB_READONLY
) ) 
 191         SetStringSelection(rsValue
); 
 193         ::WinSetWindowText(GetHwnd(), rsValue
.c_str()); 
 194 } // end of wxComboBox::SetValue 
 197 // Clipboard operations 
 199 void wxComboBox::Copy() 
 201     HWND                            hWnd 
= GetHwnd(); 
 203     ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0); 
 204 } // end of wxComboBox::Copy 
 206 void wxComboBox::Cut() 
 208     HWND                            hWnd 
= GetHwnd(); 
 210     ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0); 
 211 } // end of wxComboBox::Cut 
 213 void wxComboBox::Paste() 
 215     HWND                            hWnd 
= GetHwnd(); 
 217     ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0); 
 218 } // end of wxComboBox::Paste 
 220 void wxComboBox::SetEditable( 
 224     HWND                            hWnd 
= GetHwnd(); 
 226     ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L); 
 227 } // end of wxComboBox::SetEditable 
 229 void wxComboBox::SetInsertionPoint( 
 233     HWND                            hWnd 
= GetHwnd(); 
 235     ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0); 
 236 } // end of wxComboBox::SetInsertionPoint 
 238 void wxComboBox::SetInsertionPointEnd() 
 240     long                            lPos 
= GetLastPosition(); 
 242     SetInsertionPoint(lPos
); 
 243 } // end of wxComboBox::SetInsertionPointEnd 
 245 long wxComboBox::GetInsertionPoint() const 
 247     long                            lPos 
= LONGFROMMR(::WinSendMsg( GetHwnd() 
 252    if (lPos 
== LIT_NONE
) 
 255 } // end of wxComboBox::GetInsertionPoint 
 257 long wxComboBox::GetLastPosition() const 
 259     long                            lLineLength 
= 0L; 
 263     // Get number of characters in the last (only) line. We'll add this to the character 
 264     // index for the last line, 1st position. 
 268     vParams
.fsStatus 
= WPM_CCHTEXT
; 
 269     if (::WinSendMsg( GetHwnd() 
 270                      ,WM_QUERYWINDOWPARAMS
 
 275         lLineLength 
= (long)vParams
.cchText
; 
 280 } // end of wxComboBox::GetLastPosition 
 282 void wxComboBox::Replace( 
 285 , const wxString
&                   rsValue
 
 289     HWND                            hWnd 
= GetHwnd(); 
 292     // Set selection and remove it 
 294     ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 295     ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0); 
 298     // Now replace with 'value', by pasting. 
 300     wxSetClipboardData( wxDF_TEXT
 
 301                        ,(wxObject 
*)rsValue
.c_str() 
 307     // Paste into edit control 
 309     ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L); 
 311 } // end of wxComboBox::Replace 
 313 void wxComboBox::Remove( 
 319     HWND                            hWnd 
= GetHwnd(); 
 321     ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 322     ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0); 
 324 } // end of wxComboBox::Remove 
 326 void wxComboBox::SetSelection( 
 331     HWND                            hWnd 
= GetHwnd(); 
 336     // If from and to are both -1, it means 
 337     // (in wxWidgets) that all text should be selected. 
 338     // This translates into Windows convention 
 340     if ((lFrom 
== -1L) && (lTo 
== -1L)) 
 348                  ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
) 
 351 } // end of wxComboBox::SetSelection 
 353 void wxComboBox::DoSetSize( 
 361     wxControl::DoSetSize( nX
 
 367 } // end of wxComboBox::DoSetSize 
 369 bool wxComboBox::ProcessEditMsg( 
 378             vFlag 
= SHORT1FROMMP(wParam
); 
 382                     return (HandleChar( wParam
 
 388                     return (HandleKeyDown( wParam
 
 393                     return (HandleKeyUp( wParam
 
 400             if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
) 
 401                 return(HandleSetFocus((WXHWND
)(HWND
)wParam
)); 
 403                 return(HandleKillFocus((WXHWND
)(HWND
)wParam
)); 
 407 } // end of WinGuiBase_CComboBox::ProcessEditMsg 
 409 MRESULT EXPENTRY 
wxComboEditWndProc( 
 419         // Forward some messages to the combobox 
 424                 wxComboBox
* pCombo 
= (wxComboBox 
*)::WinQueryWindowULong( hWnd
 
 428                 if (pCombo
->ProcessEditMsg( uMessage
 
 437         // TODO: Deal with tooltips here 
 440     return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
)); 
 441 } // end of wxComboEditWndProc