X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aeab6775d8db7da3b52c16ae6f2f8e3604f6f101..7c5457867870a0a33951def66373f5a76ec3ae4a:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 63574bbefd..6ef3532c9f 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -20,35 +20,64 @@ #pragma hdrstop #endif +#include "wx/window.h" +#include "wx/msw/private.h" + #ifndef WX_PRECOMP - #include "wx/listbox.h" - #include "wx/settings.h" - #include "wx/brush.h" - #include "wx/font.h" - #include "wx/dc.h" +#include "wx/listbox.h" +#include "wx/settings.h" +#include "wx/brush.h" +#include "wx/font.h" +#include "wx/dc.h" #endif -#include "wx/msw/private.h" - -#include #include -#ifndef __TWIN32__ - #ifdef __GNUWIN32__ - #include - #endif +#ifdef __WXWINE__ + #if defined(GetWindowStyle) + #undef GetWindowStyle + #endif #endif -#ifdef GetCharWidth - #undef GetCharWidth -#endif +#include "wx/dynarray.h" +#include "wx/log.h" #if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif -#include "wx/dynarray.h" -#include "wx/log.h" +#ifndef __TWIN32__ + #if defined(__GNUWIN32__) + #include + #endif +#endif + +#ifdef __WXWINE__ + #ifndef ListBox_SetItemData + #define ListBox_SetItemData(hwndCtl, index, data) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_SETITEMDATA, (WPARAM)(int)(index), (LPARAM)(data))) + #endif + #ifndef ListBox_GetHorizontalExtent + #define ListBox_GetHorizontalExtent(hwndCtl) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_GETHORIZONTALEXTENT, 0L, 0L)) + #endif + #ifndef ListBox_GetSelCount + #define ListBox_GetSelCount(hwndCtl) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_GETSELCOUNT, 0L, 0L)) + #endif + #ifndef ListBox_GetSelItems + #define ListBox_GetSelItems(hwndCtl, cItems, lpItems) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_GETSELITEMS, (WPARAM)(int)(cItems), (LPARAM)(int *)(lpItems))) + #endif + #ifndef ListBox_GetTextLen + #define ListBox_GetTextLen(hwndCtl, index) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_GETTEXTLEN, (WPARAM)(int)(index), 0L)) + #endif + #ifndef ListBox_GetText + #define ListBox_GetText(hwndCtl, index, lpszBuffer) \ + ((int)(DWORD)SendMessage((hwndCtl), LB_GETTEXT, (WPARAM)(int)(index), (LPARAM)(LPCTSTR)(lpszBuffer))) + #endif +#endif #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) @@ -83,9 +112,6 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n) // list box control implementation // ============================================================================ -// this macro is dangerous but still better than tons of (HWND)GetHWND() -#define hwnd (HWND)GetHWND() - bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { /* @@ -104,7 +130,7 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) event.m_commandInt = aSelections[0] ; event.m_clientData = GetClientData(event.m_commandInt); wxString str(GetString(event.m_commandInt)); - if (str != "") + if (str != _T("")) { event.m_commandString = str; } @@ -168,7 +194,8 @@ bool wxListBox::Create(wxWindow *parent, int height = size.y; m_windowStyle = style; - DWORD wstyle = WS_VSCROLL | WS_TABSTOP | LBS_NOTIFY | LBS_HASSTRINGS; + DWORD wstyle = WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | + LBS_NOTIFY | LBS_HASSTRINGS; if (m_windowStyle & wxLB_MULTIPLE) wstyle |= LBS_MULTIPLESEL; else if (m_windowStyle & wxLB_EXTENDED) @@ -202,18 +229,18 @@ bool wxListBox::Create(wxWindow *parent, wstyle |= WS_BORDER; } - m_hWnd = (WXHWND)::CreateWindowEx(exStyle, "LISTBOX", NULL, + m_hWnd = (WXHWND)::CreateWindowEx(exStyle, _T("LISTBOX"), NULL, wstyle | WS_CHILD, 0, 0, 0, 0, (HWND)parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - wxCHECK_MSG( m_hWnd, FALSE, "Failed to create listbox" ); + wxCHECK_MSG( m_hWnd, FALSE, _T("Failed to create listbox") ); #if wxUSE_CTL3D if (want3D) { - Ctl3dSubclassCtl(hwnd); + Ctl3dSubclassCtl(GetHwnd()); m_useCtl3D = TRUE; } #endif @@ -227,7 +254,7 @@ bool wxListBox::Create(wxWindow *parent, } if ( (m_windowStyle & wxLB_MULTIPLE) == 0 ) - SendMessage(hwnd, LB_SETCURSEL, 0, 0); + SendMessage(GetHwnd(), LB_SETCURSEL, 0, 0); SetFont(parent->GetFont()); @@ -257,9 +284,9 @@ void wxListBox::SetupColours() void wxListBox::SetFirstItem(int N) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::SetFirstItem" ); + _T("invalid index in wxListBox::SetFirstItem") ); - SendMessage(hwnd,LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ; + SendMessage(GetHwnd(),LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ; } void wxListBox::SetFirstItem(const wxString& s) @@ -273,9 +300,9 @@ void wxListBox::SetFirstItem(const wxString& s) void wxListBox::Delete(int N) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::Delete" ); + _T("invalid index in wxListBox::Delete") ); - SendMessage(hwnd, LB_DELETESTRING, N, 0); + SendMessage(GetHwnd(), LB_DELETESTRING, N, 0); m_noItems--; SetHorizontalExtent(""); @@ -283,7 +310,7 @@ void wxListBox::Delete(int N) void wxListBox::Append(const wxString& item) { - int index = ListBox_AddString(hwnd, item); + int index = ListBox_AddString(GetHwnd(), item); m_noItems ++; #if wxUSE_OWNER_DRAWN @@ -291,42 +318,42 @@ void wxListBox::Append(const wxString& item) wxOwnerDrawn *pNewItem = CreateItem(index); // dummy argument pNewItem->SetName(item); m_aItems.Add(pNewItem); - ListBox_SetItemData(hwnd, index, pNewItem); + ListBox_SetItemData(GetHwnd(), index, pNewItem); } #endif SetHorizontalExtent(item); } -void wxListBox::Append(const wxString& item, char *Client_data) +void wxListBox::Append(const wxString& item, void *Client_data) { - int index = ListBox_AddString(hwnd, item); + int index = ListBox_AddString(GetHwnd(), item); m_noItems ++; #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { // client data must be pointer to wxOwnerDrawn, otherwise we would crash // in OnMeasure/OnDraw. - wxFAIL_MSG("Can't use client data with owner-drawn listboxes"); + wxFAIL_MSG(_T("Can't use client data with owner-drawn listboxes")); } else #endif - ListBox_SetItemData(hwnd, index, Client_data); + ListBox_SetItemData(GetHwnd(), index, Client_data); SetHorizontalExtent(item); } -void wxListBox::Set(int n, const wxString *choices, char** clientData) +void wxListBox::Set(int n, const wxString *choices, void** clientData) { - ShowWindow(hwnd, SW_HIDE); - ListBox_ResetContent(hwnd); + ShowWindow(GetHwnd(), SW_HIDE); + ListBox_ResetContent(GetHwnd()); int i; for (i = 0; i < n; i++) { - ListBox_AddString(hwnd, choices[i]); + ListBox_AddString(GetHwnd(), choices[i]); if ( clientData ) - ListBox_SetItemData(hwnd, i, clientData[i]); + ListBox_SetItemData(GetHwnd(), i, clientData[i]); } m_noItems = n; @@ -344,21 +371,21 @@ void wxListBox::Set(int n, const wxString *choices, char** clientData) wxOwnerDrawn *pNewItem = CreateItem(ui); pNewItem->SetName(choices[ui]); m_aItems.Add(pNewItem); - ListBox_SetItemData(hwnd, ui, pNewItem); + ListBox_SetItemData(GetHwnd(), ui, pNewItem); wxASSERT_MSG(clientData[ui] == NULL, - "Can't use client data with owner-drawn listboxes"); + _T("Can't use client data with owner-drawn listboxes")); } } #endif SetHorizontalExtent(""); - ShowWindow(hwnd, SW_SHOW); + ShowWindow(GetHwnd(), SW_SHOW); } int wxListBox::FindString(const wxString& s) const { - int pos = ListBox_FindStringExact(hwnd, (WPARAM)-1, s); + int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s); if (pos == LB_ERR) return -1; else @@ -367,7 +394,7 @@ int wxListBox::FindString(const wxString& s) const void wxListBox::Clear() { - ListBox_ResetContent(hwnd); + ListBox_ResetContent(GetHwnd()); #if wxUSE_OWNER_DRAWN size_t uiCount = m_aItems.Count(); @@ -379,57 +406,57 @@ void wxListBox::Clear() #endif // wxUSE_OWNER_DRAWN m_noItems = 0; - ListBox_GetHorizontalExtent(hwnd); + ListBox_GetHorizontalExtent(GetHwnd()); } void wxListBox::SetSelection(int N, bool select) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::SetSelection" ); + _T("invalid index in wxListBox::SetSelection") ); if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) - SendMessage(hwnd, LB_SETSEL, select, N); + SendMessage(GetHwnd(), LB_SETSEL, select, N); else { int N1 = N; if (!select) N1 = -1; - SendMessage(hwnd, LB_SETCURSEL, N1, 0); + SendMessage(GetHwnd(), LB_SETCURSEL, N1, 0); } } bool wxListBox::Selected(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, - "invalid index in wxListBox::Selected" ); + _T("invalid index in wxListBox::Selected") ); - return SendMessage(hwnd, LB_GETSEL, N, 0) == 0 ? FALSE : TRUE; + return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? FALSE : TRUE; } void wxListBox::Deselect(int N) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::Deselect" ); + _T("invalid index in wxListBox::Deselect") ); if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) - SendMessage(hwnd, LB_SETSEL, FALSE, N); + SendMessage(GetHwnd(), LB_SETSEL, FALSE, N); } -char *wxListBox::GetClientData(int N) const +void *wxListBox::GetClientData(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, - "invalid index in wxListBox::GetClientData" ); + _T("invalid index in wxListBox::GetClientData") ); - return (char *)SendMessage(hwnd, LB_GETITEMDATA, N, 0); + return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, N, 0); } -void wxListBox::SetClientData(int N, char *Client_data) +void wxListBox::SetClientData(int N, void *Client_data) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::SetClientData" ); + _T("invalid index in wxListBox::SetClientData") ); - if ( ListBox_SetItemData(hwnd, N, Client_data) == LB_ERR ) - wxLogDebug("LB_SETITEMDATA failed"); + if ( ListBox_SetItemData(GetHwnd(), N, Client_data) == LB_ERR ) + wxLogDebug(_T("LB_SETITEMDATA failed")); } // Return number of selections and an array of selected integers @@ -439,11 +466,11 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) { - int no_sel = ListBox_GetSelCount(hwnd); + int no_sel = ListBox_GetSelCount(GetHwnd()); if (no_sel != 0) { int *selections = new int[no_sel]; - if ( ListBox_GetSelItems(hwnd, no_sel, selections) == LB_ERR ) { - wxFAIL_MSG("This listbox can't have single-selection style!"); + if ( ListBox_GetSelItems(GetHwnd(), no_sel, selections) == LB_ERR ) { + wxFAIL_MSG(_T("This listbox can't have single-selection style!")); } aSelections.Alloc(no_sel); @@ -457,7 +484,7 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const } else // single-selection listbox { - aSelections.Add(ListBox_GetCurSel(hwnd)); + aSelections.Add(ListBox_GetCurSel(GetHwnd())); return 1; } @@ -469,23 +496,23 @@ int wxListBox::GetSelection() const wxCHECK_MSG( !(m_windowStyle & wxLB_MULTIPLE) && !(m_windowStyle & wxLB_EXTENDED), -1, - "GetSelection() can't be used with multiple-selection " - "listboxes, use GetSelections() instead." ); + _T("GetSelection() can't be used with multiple-selection " + "listboxes, use GetSelections() instead.") ); - return ListBox_GetCurSel(hwnd); + return ListBox_GetCurSel(GetHwnd()); } // Find string for position wxString wxListBox::GetString(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, "", - "invalid index in wxListBox::GetClientData" ); + _T("invalid index in wxListBox::GetClientData") ); - int len = ListBox_GetTextLen(hwnd, N); + int len = ListBox_GetTextLen(GetHwnd(), N); // +1 for terminating NUL wxString result; - ListBox_GetText(hwnd, N, result.GetWriteBuf(len + 1)); + ListBox_GetText(GetHwnd(), N, result.GetWriteBuf(len + 1)); result.UngetWriteBuf(); return result; @@ -540,7 +567,7 @@ void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (control_width <= 0) control_width = (float)DEFAULT_ITEM_WIDTH; - MoveWindow(hwnd, + MoveWindow(GetHwnd(), (int)control_x, (int)control_y, (int)control_width, (int)control_height, TRUE); @@ -558,31 +585,31 @@ void wxListBox::SetHorizontalExtent(const wxString& s) return; TEXTMETRIC lpTextMetric; - if (s != "") + if (s != _T("")) { - int existingExtent = (int)SendMessage(hwnd, LB_GETHORIZONTALEXTENT, 0, 0L); - HDC dc = GetWindowDC(hwnd); + int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L); + HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; if (GetFont().Ok() && GetFont().GetResourceHandle()) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); SIZE extentXY; - ::GetTextExtentPoint(dc, (LPSTR) (const char *)s, s.Length(), &extentXY); + ::GetTextExtentPoint(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY); int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth); if (oldFont) ::SelectObject(dc, oldFont); - ReleaseDC(hwnd, dc); + ReleaseDC(GetHwnd(), dc); if (extentX > existingExtent) - SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L); + SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L); return; } else { int largestExtent = 0; - HDC dc = GetWindowDC(hwnd); + HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; if (GetFont().Ok() && GetFont().GetResourceHandle()) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); @@ -591,10 +618,10 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int i; for (i = 0; i < m_noItems; i++) { - int len = (int)SendMessage(hwnd, LB_GETTEXT, i, (LONG)wxBuffer); + int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LONG)wxBuffer); wxBuffer[len] = 0; SIZE extentXY; - ::GetTextExtentPoint(dc, (LPSTR)wxBuffer, len, &extentXY); + ::GetTextExtentPoint(dc, (LPTSTR)wxBuffer, len, &extentXY); int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth); if (extentX > largestExtent) largestExtent = extentX; @@ -602,8 +629,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) if (oldFont) ::SelectObject(dc, oldFont); - ReleaseDC(hwnd, dc); - SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L); + ReleaseDC(GetHwnd(), dc); + SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L); } } @@ -611,34 +638,34 @@ void wxListBox::InsertItems(int nItems, const wxString items[], int pos) { wxCHECK_RET( pos >= 0 && pos <= m_noItems, - "invalid index in wxListBox::InsertItems" ); + _T("invalid index in wxListBox::InsertItems") ); int i; for (i = 0; i < nItems; i++) - ListBox_InsertString(hwnd, i + pos, items[i]); + ListBox_InsertString(GetHwnd(), i + pos, items[i]); m_noItems += nItems; - SetHorizontalExtent(""); + SetHorizontalExtent(_T("")); } void wxListBox::SetString(int N, const wxString& s) { wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::SetString" ); + _T("invalid index in wxListBox::SetString") ); int sel = -1; if (!(m_windowStyle & wxLB_MULTIPLE) && !(m_windowStyle & wxLB_EXTENDED)) sel = GetSelection(); - char *oldData = (char *)wxListBox::GetClientData(N); + void *oldData = wxListBox::GetClientData(N); - SendMessage(hwnd, LB_DELETESTRING, N, 0); + SendMessage(GetHwnd(), LB_DELETESTRING, N, 0); int newN = N; if (N == (m_noItems - 1)) newN = -1; - SendMessage(hwnd, LB_INSERTSTRING, newN, (LPARAM) (const char *)s); + SendMessage(GetHwnd(), LB_INSERTSTRING, newN, (LPARAM) (const wxChar *)s); if (oldData) wxListBox::SetClientData(N, oldData); @@ -752,7 +779,7 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item) MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item; wxDC dc; - dc.SetHDC((WXHDC)CreateIC("DISPLAY", NULL, NULL, 0)); + dc.SetHDC((WXHDC)CreateIC(_T("DISPLAY"), NULL, NULL, 0)); dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_ANSI_VAR_FONT)); pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE; @@ -769,7 +796,7 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item; - long data = ListBox_GetItemData(hwnd, pStruct->itemID); + long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID); wxCHECK( data && (data != LB_ERR), FALSE );