X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1169a91932273bc84c23ed9dbd0a2da064d59d66..304b8bc189e7d1d51cf8012aa9708fced31b987e:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 80b2bb0f6f..d4ca4c4c87 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -155,19 +155,6 @@ wxListBox::wxListBox() m_selected = 0; } -wxListBox::wxListBox(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - int n, - const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name) -{ - Create(parent, id, pos, size, n, choices, style, validator, name); -} - bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, @@ -178,101 +165,88 @@ bool wxListBox::Create(wxWindow *parent, const wxString& name) { m_noItems = 0; - m_hWnd = 0; m_selected = 0; - SetName(name); -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif // wxUSE_VALIDATORS - - if (parent) - parent->AddChild(this); - - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(parent->GetForegroundColour()); - - m_windowId = ( id == -1 ) ? (int)NewControlId() : id; - - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - m_windowStyle = style; - - DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_TABSTOP | - LBS_NOTIFY | LBS_HASSTRINGS ; + // initialize base class fields + if ( !CreateControl(parent, id, pos, size, style, validator, name) ) + return false; - wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), - _T("only one of listbox selection modes can be specified") ); - - if ( (m_windowStyle & wxBORDER_MASK) == wxBORDER_DEFAULT ) - m_windowStyle |= wxBORDER_SUNKEN; - - if ( m_windowStyle & wxCLIP_SIBLINGS ) - wstyle |= WS_CLIPSIBLINGS; - - if (m_windowStyle & wxLB_MULTIPLE) - wstyle |= LBS_MULTIPLESEL; - else if (m_windowStyle & wxLB_EXTENDED) - wstyle |= LBS_EXTENDEDSEL; - - if (m_windowStyle & wxLB_ALWAYS_SB) - wstyle |= LBS_DISABLENOSCROLL; - if (m_windowStyle & wxLB_HSCROLL) - wstyle |= WS_HSCROLL; - if (m_windowStyle & wxLB_SORT) - wstyle |= LBS_SORT; + // create the native control + if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString, pos, size) ) + { + // control creation failed + return false; + } -#if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__) - if ( m_windowStyle & wxLB_OWNERDRAW ) { - // we don't support LBS_OWNERDRAWVARIABLE yet - wstyle |= LBS_OWNERDRAWFIXED; + // initialize the contents + for ( int i = 0; i < n; i++ ) + { + Append(choices[i]); } -#endif - // Without this style, you get unexpected heights, so e.g. constraint layout - // doesn't work properly - wstyle |= LBS_NOINTEGRALHEIGHT; + return true; +} - WXDWORD exStyle = 0; - (void) MSWGetStyle(m_windowStyle, & exStyle) ; +bool wxListBox::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name) +{ + wxCArrayString chs(choices); + return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(), + style, validator, name); +} - m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("LISTBOX"), NULL, - wstyle , - 0, 0, 0, 0, - (HWND)parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); +wxListBox::~wxListBox() +{ + Free(); +} - wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create listbox") ); +WXDWORD wxListBox::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); - // Subclass again to catch messages - SubclassWin(m_hWnd); + // always show the vertical scrollbar if necessary -- otherwise it is + // impossible to use the control with the mouse + msStyle |= WS_VSCROLL; - size_t ui; - for (ui = 0; ui < (size_t)n; ui++) { - Append(choices[ui]); - } + // we always want to get the notifications + msStyle |= LBS_NOTIFY; - if ( (m_windowStyle & wxLB_MULTIPLE) == 0 ) - SendMessage(GetHwnd(), LB_SETCURSEL, 0, 0); + // without this style, you get unexpected heights, so e.g. constraint + // layout doesn't work properly + msStyle |= LBS_NOINTEGRALHEIGHT; - SetFont(parent->GetFont()); + wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), + _T("only one of listbox selection modes can be specified") ); - SetSize(x, y, width, height); + if ( style & wxLB_MULTIPLE ) + msStyle |= LBS_MULTIPLESEL; + else if ( style & wxLB_EXTENDED ) + msStyle |= LBS_EXTENDEDSEL; - return TRUE; -} + if ( m_windowStyle & wxLB_ALWAYS_SB ) + msStyle |= LBS_DISABLENOSCROLL; + if ( m_windowStyle & wxLB_HSCROLL ) + msStyle |= WS_HSCROLL; + if ( m_windowStyle & wxLB_SORT ) + msStyle |= LBS_SORT; -wxListBox::~wxListBox() -{ - Free(); -} +#if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__) + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put + // the strings in the listbox for simplicity even though we could have + // avoided it in this case + msStyle |= LBS_OWNERDRAWFIXED | LBS_HASSTRINGS; + } +#endif // wxUSE_OWNER_DRAWN -void wxListBox::SetupColours() -{ - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(GetParent()->GetForegroundColour()); + return msStyle; } // ---------------------------------------------------------------------------- @@ -598,10 +572,6 @@ void wxListBox::SetString(int N, const wxString& s) else if ( oldObjData ) SetClientObject(N, oldObjData); - // we may have lost the selection - if ( wasSelected ) - Select(N); - #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { @@ -612,6 +582,10 @@ void wxListBox::SetString(int N, const wxString& s) ListBox_SetItemData(GetHwnd(), N, m_aItems[N]); } #endif //USE_OWNER_DRAWN + + // we may have lost the selection + if ( wasSelected ) + Select(N); } int wxListBox::GetCount() const