X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..520e470fdd0daef09c77938db642e4583933c90d:/src/msw/combobox.cpp diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index 5c7888dab5..db6801a3f3 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -24,7 +24,7 @@ #include "wx/setup.h" #endif -#if USE_COMBOBOX +#if wxUSE_COMBOBOX #include "wx/combobox.h" #include "wx/clipbrd.h" @@ -34,11 +34,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) #endif -bool wxComboBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) +bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { if (param == CBN_SELCHANGE) { - wxCommandEvent event(wxEVENT_TYPE_COMBOBOX_COMMAND, m_windowId); + wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId); event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(copystring(GetStringSelection())); @@ -46,43 +46,53 @@ bool wxComboBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) delete[] event.GetString(); return TRUE; } + else if (param == CBN_EDITCHANGE) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event.SetString(copystring(GetValue())); + event.SetEventObject(this); + ProcessCommand(event); + delete[] event.GetString(); + return TRUE; + } else return FALSE; } -bool wxComboBox::Create(wxWindow *parent, const wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - const int n, const wxString choices[], - const long style, - const wxValidator& validator, - const wxString& name) +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) { SetName(name); SetValidator(validator); if (parent) parent->AddChild(this); - SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; - SetForegroundColour(parent->GetDefaultForegroundColour()) ; - no_strings = n; + SetBackgroundColour(parent->GetBackgroundColour()) ; + SetForegroundColour(parent->GetForegroundColour()) ; + m_noStrings = n; m_windowStyle = style; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; int width = size.x; int height = size.y; - long msStyle = WS_CHILD | WS_HSCROLL | WS_VSCROLL - | WS_TABSTOP | WS_VISIBLE | CBS_NOINTEGRALHEIGHT; + long msStyle = WS_CHILD | WS_HSCROLL | WS_VSCROLL | + WS_TABSTOP | WS_VISIBLE | CBS_NOINTEGRALHEIGHT; + if (m_windowStyle & wxCB_READONLY) msStyle |= CBS_DROPDOWNLIST; - else if (m_windowStyle & wxCB_SIMPLE) // A list (shown always) and edit control - msStyle |= CBS_SIMPLE; + else if (m_windowStyle & wxCB_SIMPLE) + msStyle |= CBS_SIMPLE; // A list (shown always) and edit control else msStyle |= CBS_DROPDOWN; @@ -94,14 +104,16 @@ bool wxComboBox::Create(wxWindow *parent, const wxWindowID id, // Even with extended styles, need to combine with WS_BORDER // for them to look right. - if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || - (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER)) + if ( want3D || wxStyleHasBorder(m_windowStyle) ) msStyle |= WS_BORDER; - HWND wx_combo = CreateWindowEx(exStyle, "COMBOBOX", NULL, + m_hWnd = (WXHWND)::CreateWindowEx(exStyle, "COMBOBOX", NULL, msStyle, 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); + + wxCHECK_MSG( m_hWnd, FALSE, "Failed to create combobox" ); + /* #if CTL3D if (want3D) @@ -112,28 +124,30 @@ bool wxComboBox::Create(wxWindow *parent, const wxWindowID id, #endif */ - m_hWnd = (WXHWND)wx_combo; - // Subclass again for purposes of dialog editing mode - SubclassWin((WXHWND)wx_combo); + SubclassWin(m_hWnd); SetFont(* parent->GetFont()); int i; for (i = 0; i < n; i++) - SendMessage(wx_combo, CB_INSERTSTRING, i, (LONG)(const char *)choices[i]); - SendMessage(wx_combo, CB_SETCURSEL, i, 0); + { + Append(choices[i]); + } + + SetSelection(i); SetSize(x, y, width, height); - if ( value != "" ) - SetWindowText(wx_combo, (const char *)value); + if ( !value.IsEmpty() ) + { + SetValue(value); + } return TRUE; } -wxString wxComboBox::GetValue(void) const +wxString wxComboBox::GetValue() const { - GetWindowText((HWND) GetHWND(), wxBuffer, 500); - return wxString(wxBuffer); + return wxGetWindowText(GetHWND()); } void wxComboBox::SetValue(const wxString& value) @@ -170,32 +184,32 @@ void wxComboBox::SetValue(const wxString& value) } // Clipboard operations -void wxComboBox::Copy(void) +void wxComboBox::Copy() { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, WM_COPY, 0, 0L); } -void wxComboBox::Cut(void) +void wxComboBox::Cut() { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, WM_CUT, 0, 0L); } -void wxComboBox::Paste(void) +void wxComboBox::Paste() { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, WM_PASTE, 0, 0L); } -void wxComboBox::SetEditable(const bool editable) +void wxComboBox::SetEditable(bool editable) { // Can't implement in MSW? // HWND hWnd = (HWND) GetHWND(); // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); } -void wxComboBox::SetInsertionPoint(const long pos) +void wxComboBox::SetInsertionPoint(long pos) { /* HWND hWnd = (HWND) GetHWND(); @@ -210,7 +224,7 @@ void wxComboBox::SetInsertionPoint(const long pos) */ } -void wxComboBox::SetInsertionPointEnd(void) +void wxComboBox::SetInsertionPointEnd() { /* long pos = GetLastPosition(); @@ -218,7 +232,7 @@ void wxComboBox::SetInsertionPointEnd(void) */ } -long wxComboBox::GetInsertionPoint(void) const +long wxComboBox::GetInsertionPoint() const { /* DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L); @@ -227,7 +241,7 @@ long wxComboBox::GetInsertionPoint(void) const return 0; } -long wxComboBox::GetLastPosition(void) const +long wxComboBox::GetLastPosition() const { /* HWND hWnd = (HWND) GetHWND(); @@ -247,9 +261,9 @@ long wxComboBox::GetLastPosition(void) const return 0; } -void wxComboBox::Replace(const long from, const long to, const wxString& value) +void wxComboBox::Replace(long from, long to, const wxString& value) { -#if USE_CLIPBOARD +#if wxUSE_CLIPBOARD HWND hWnd = (HWND) GetHWND(); long fromChar = from; long toChar = to; @@ -263,14 +277,14 @@ void wxComboBox::Replace(const long from, const long to, const wxString& value) SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); // Now replace with 'value', by pasting. - wxSetClipboardData(wxCF_TEXT, (wxObject *)(const char *)value, 0, 0); + wxSetClipboardData(wxDF_TEXT, (wxObject *)(const char *)value, 0, 0); // Paste into edit control SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L); #endif } -void wxComboBox::Remove(const long from, const long to) +void wxComboBox::Remove(long from, long to) { HWND hWnd = (HWND) GetHWND(); long fromChar = from; @@ -285,7 +299,7 @@ void wxComboBox::Remove(const long from, const long to) SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); } -void wxComboBox::SetSelection(const long from, const long to) +void wxComboBox::SetSelection(long from, long to) { HWND hWnd = (HWND) GetHWND(); long fromChar = from; @@ -309,5 +323,5 @@ void wxComboBox::SetSelection(const long from, const long to) } #endif - // USE_COMBOBOX + // wxUSE_COMBOBOX