X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ab22cb9a01d7412ce53429806aa9650df7483cd4..3d05544e4e71e7ff10984dae5a9b8a07d92f42a6:/src/msw/listbox.cpp?ds=sidebyside diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index efa19846bd..d5348816b6 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -23,6 +23,9 @@ #ifndef WX_PRECOMP #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" @@ -38,7 +41,7 @@ #undef GetCharWidth #endif -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif @@ -53,7 +56,7 @@ // list box item declaration and implementation // ============================================================================ -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN class wxListBoxItem : public wxOwnerDrawn { @@ -67,7 +70,7 @@ wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE) SetMarginWidth(0); } -wxOwnerDrawn *wxListBox::CreateItem(uint n) +wxOwnerDrawn *wxListBox::CreateItem(size_t n) { return new wxListBoxItem(); } @@ -81,7 +84,7 @@ wxOwnerDrawn *wxListBox::CreateItem(uint n) // this macro is dangerous but still better than tons of (HWND)GetHWND() #define hwnd (HWND)GetHWND() -bool wxListBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) +bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { /* if (param == LBN_SELCANCEL) @@ -118,7 +121,9 @@ bool wxListBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) { wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId); event.SetEventObject( this ); - if ( !GetEventHandler()->ProcessEvent(event) ) + GetEventHandler()->ProcessEvent(event) ; + return TRUE; +/* { #if WXWIN_COMPATIBILITY wxWindow *parent = (wxWindow *)GetParent(); @@ -127,6 +132,7 @@ bool wxListBox::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id)) #endif return TRUE; } + */ } return FALSE; } @@ -138,15 +144,15 @@ wxListBox::wxListBox(void) m_selected = 0; } -bool wxListBox::Create(wxWindow *parent, const wxWindowID id, +bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, - const int n, const wxString choices[], - const long style, + int n, const wxString choices[], + long style, const wxValidator& validator, const wxString& name) { - m_noItems = n; + m_noItems = 0; m_hWnd = 0; m_selected = 0; @@ -157,7 +163,7 @@ bool wxListBox::Create(wxWindow *parent, const wxWindowID id, wxSystemSettings settings; SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(parent->GetDefaultForegroundColour()); + SetForegroundColour(parent->GetForegroundColour()); m_windowId = ( id == -1 ) ? (int)NewControlId() : id; @@ -180,7 +186,7 @@ bool wxListBox::Create(wxWindow *parent, const wxWindowID id, if (m_windowStyle & wxLB_SORT) wstyle |= LBS_SORT; -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { // we don't support LBS_OWNERDRAWVARIABLE yet wstyle |= LBS_OWNERDRAWFIXED; @@ -195,65 +201,65 @@ bool wxListBox::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) ) + { wstyle |= WS_BORDER; } - HWND wx_list = CreateWindowEx(exStyle, "LISTBOX", NULL, + m_hWnd = (WXHWND)::CreateWindowEx(exStyle, "LISTBOX", NULL, wstyle | WS_CHILD, 0, 0, 0, 0, (HWND)parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - m_hWnd = (WXHWND)wx_list; + wxCHECK_MSG( m_hWnd, FALSE, "Failed to create listbox" ); #if CTL3D if (want3D) { - Ctl3dSubclassCtl(wx_list); + Ctl3dSubclassCtl(hwnd); m_useCtl3D = TRUE; } #endif // Subclass again to catch messages - SubclassWin((WXHWND)wx_list); + SubclassWin(m_hWnd); - uint ui; - for (ui = 0; ui < (uint)n; ui++) { - SendMessage(wx_list, LB_ADDSTRING, 0, (LPARAM)(const char *)choices[ui]); + size_t ui; + for (ui = 0; ui < (size_t)n; ui++) { + Append(choices[ui]); } -#if USE_OWNER_DRAWN + /* Not needed -- done in Append +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { - for (ui = 0; ui < (uint)n; ui++) { + for (ui = 0; ui < (size_t)n; ui++) { // create new item which will process WM_{DRAW|MEASURE}ITEM messages wxOwnerDrawn *pNewItem = CreateItem(ui); pNewItem->SetName(choices[ui]); m_aItems.Add(pNewItem); - ListBox_SetItemData(wx_list, ui, pNewItem); + ListBox_SetItemData(hwnd, ui, pNewItem); } } #endif +*/ - if ((m_windowStyle & wxLB_MULTIPLE) == 0) - SendMessage(wx_list, LB_SETCURSEL, 0, 0); + if ( (m_windowStyle & wxLB_MULTIPLE) == 0 ) + SendMessage(hwnd, LB_SETCURSEL, 0, 0); - SetFont(* parent->GetFont()); + SetFont(parent->GetFont()); SetSize(x, y, width, height); - ShowWindow(wx_list, SW_SHOW); + Show(TRUE); return TRUE; } wxListBox::~wxListBox(void) { -#if USE_OWNER_DRAWN - uint uiCount = m_aItems.Count(); +#if wxUSE_OWNER_DRAWN + size_t uiCount = m_aItems.Count(); while ( uiCount-- != 0 ) { delete m_aItems[uiCount]; } @@ -263,10 +269,10 @@ wxListBox::~wxListBox(void) void wxListBox::SetupColours(void) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(GetParent()->GetDefaultForegroundColour()); + SetForegroundColour(GetParent()->GetForegroundColour()); } -void wxListBox::SetFirstItem(const int N) +void wxListBox::SetFirstItem(int N) { SendMessage(hwnd,LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ; } @@ -279,7 +285,7 @@ void wxListBox::SetFirstItem(const wxString& s) SetFirstItem(N) ; } -void wxListBox::Delete(const int N) +void wxListBox::Delete(int N) { SendMessage(hwnd, LB_DELETESTRING, N, 0); m_noItems --; @@ -291,9 +297,9 @@ void wxListBox::Append(const wxString& item) int index = ListBox_AddString(hwnd, item); m_noItems ++; -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { - wxOwnerDrawn *pNewItem = CreateItem(-1); // dummy argument + wxOwnerDrawn *pNewItem = CreateItem(index); // dummy argument pNewItem->SetName(item); m_aItems.Add(pNewItem); ListBox_SetItemData(hwnd, index, pNewItem); @@ -308,7 +314,7 @@ void wxListBox::Append(const wxString& item, char *Client_data) int index = ListBox_AddString(hwnd, item); m_noItems ++; -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { // client data must be pointer to wxOwnerDrawn, otherwise we would crash // in OnMeasure/OnDraw. @@ -321,7 +327,7 @@ void wxListBox::Append(const wxString& item, char *Client_data) SetHorizontalExtent(item); } -void wxListBox::Set(const int n, const wxString *choices, char** clientData) +void wxListBox::Set(int n, const wxString *choices, char** clientData) { ShowWindow(hwnd, SW_HIDE); ListBox_ResetContent(hwnd); @@ -334,17 +340,17 @@ void wxListBox::Set(const int n, const wxString *choices, char** clientData) } m_noItems = n; -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { // first delete old items - uint ui = m_aItems.Count(); + size_t ui = m_aItems.Count(); while ( ui-- != 0 ) { delete m_aItems[ui]; } m_aItems.Empty(); // then create new ones - for (ui = 0; ui < (uint)n; ui++) { + for (ui = 0; ui < (size_t)n; ui++) { wxOwnerDrawn *pNewItem = CreateItem(ui); pNewItem->SetName(choices[ui]); m_aItems.Add(pNewItem); @@ -377,7 +383,7 @@ void wxListBox::Clear(void) ListBox_GetHorizontalExtent(hwnd); } -void wxListBox::SetSelection(const int N, const bool select) +void wxListBox::SetSelection(int N, bool select) { if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) SendMessage(hwnd, LB_SETSEL, select, N); @@ -390,23 +396,23 @@ void wxListBox::SetSelection(const int N, const bool select) } } -bool wxListBox::Selected(const int N) const +bool wxListBox::Selected(int N) const { return SendMessage(hwnd, LB_GETSEL, N, 0) == 0 ? FALSE : TRUE; } -void wxListBox::Deselect(const int N) +void wxListBox::Deselect(int N) { if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) SendMessage(hwnd, LB_SETSEL, FALSE, N); } -char *wxListBox::GetClientData(const int N) const +char *wxListBox::GetClientData(int N) const { return (char *)SendMessage(hwnd, LB_GETITEMDATA, N, 0); } -void wxListBox::SetClientData(const int N, char *Client_data) +void wxListBox::SetClientData(int N, char *Client_data) { if ( ListBox_SetItemData(hwnd, N, Client_data) == LB_ERR ) wxLogDebug("LB_SETITEMDATA failed"); @@ -456,7 +462,7 @@ int wxListBox::GetSelection() const } // Find string for position -wxString wxListBox::GetString(const int N) const +wxString wxListBox::GetString(int N) const { if (N < 0 || N > m_noItems) return wxString(""); @@ -466,7 +472,7 @@ wxString wxListBox::GetString(const int N) const return wxString(wxBuffer); } -void wxListBox::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags) { int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -481,6 +487,8 @@ void wxListBox::SetSize(const int x, const int y, const int width, const int hei if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) y1 = currentY; + AdjustForParentClientOrigin(x1, y1, sizeFlags); + // If we're prepared to use the existing size, then... if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) { @@ -490,7 +498,7 @@ void wxListBox::SetSize(const int x, const int y, const int width, const int hei int cx; // button font dimensions int cy; - wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); + wxGetCharSize(GetHWND(), &cx, &cy, & GetFont()); float control_width, control_height, control_x, control_y; @@ -517,16 +525,6 @@ void wxListBox::SetSize(const int x, const int y, const int width, const int hei MoveWindow(hwnd, (int)control_x, (int)control_y, (int)control_width, (int)control_height, TRUE); -/* -#if WXWIN_COMPATIBILITY - GetEventHandler()->OldOnSize(width, height); -#else - wxSizeEvent event(wxSize(width, height), m_windowId); - event.eventObject = this; - GetEventHandler()->ProcessEvent(event); -#endif -*/ - } // Windows-specific code to set the horizontal extent of @@ -545,8 +543,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int existingExtent = (int)SendMessage(hwnd, LB_GETHORIZONTALEXTENT, 0, 0L); HDC dc = GetWindowDC(hwnd); HFONT oldFont = 0; - if (GetFont() && GetFont()->GetResourceHandle()) - oldFont = ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle()); + if (GetFont().Ok() && GetFont().GetResourceHandle()) + oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); SIZE extentXY; @@ -566,8 +564,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int largestExtent = 0; HDC dc = GetWindowDC(hwnd); HFONT oldFont = 0; - if (GetFont() && GetFont()->GetResourceHandle()) - oldFont = ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle()); + if (GetFont().Ok() && GetFont().GetResourceHandle()) + oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); int i; @@ -590,19 +588,19 @@ void wxListBox::SetHorizontalExtent(const wxString& s) } void -wxListBox::InsertItems(const int nItems, const wxString items[], const int pos) +wxListBox::InsertItems(int nItems, const wxString items[], int pos) { int i; for (i = 0; i < nItems; i++) ListBox_InsertString(hwnd, i + pos, items[i]); m_noItems += nItems; - #if USE_OWNER_DRAWN + #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { for ( i = 0; i < nItems; i++ ) { - wxOwnerDrawn *pNewItem = CreateItem((uint)(pos + i)); + wxOwnerDrawn *pNewItem = CreateItem((size_t)(pos + i)); pNewItem->SetName(items[i]); - m_aItems.Insert(pNewItem, (uint)(pos + i)); + m_aItems.Insert(pNewItem, (size_t)(pos + i)); ListBox_SetItemData(hwnd, i, pNewItem); } } @@ -611,9 +609,11 @@ wxListBox::InsertItems(const int nItems, const wxString items[], const int pos) SetHorizontalExtent(""); } -void wxListBox::SetString(const int N, const wxString& s) +void wxListBox::SetString(int N, const wxString& s) { - int sel = GetSelection(); + int sel = -1; + if (!(m_windowStyle & wxLB_MULTIPLE) && !(m_windowStyle & wxLB_EXTENDED)) + sel = GetSelection(); char *oldData = (char *)wxListBox::GetClientData(N); @@ -631,7 +631,7 @@ void wxListBox::SetString(const int N, const wxString& s) if (sel >= 0) SetSelection(sel); -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) // update item's text m_aItems[N]->SetName(s); @@ -653,7 +653,7 @@ wxString wxListBox::GetStringSelection (void) const return wxString(""); } -bool wxListBox::SetStringSelection (const wxString& s, const bool flag) +bool wxListBox::SetStringSelection (const wxString& s, bool flag) { int sel = FindString (s); if (sel > -1) @@ -683,7 +683,7 @@ void wxListBox::Command (wxCommandEvent & event) ProcessCommand (event); } -WXHBRUSH wxListBox::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, +WXHBRUSH wxListBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { #if CTL3D @@ -712,6 +712,7 @@ WXHBRUSH wxListBox::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { +#if 0 switch (nMsg) { case WM_INITDIALOG: @@ -732,9 +733,9 @@ long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_MOUSEMOVE: - case WM_DESTROY: case WM_COMMAND: case WM_NOTIFY: + case WM_DESTROY: case WM_MENUSELECT: case WM_INITMENUPOPUP: case WM_DRAWITEM: @@ -761,10 +762,12 @@ long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) case WM_NCHITTEST: return MSWDefWindowProc(nMsg, wParam, lParam ); } +#endif + return wxControl::MSWWindowProc(nMsg, wParam, lParam); } -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN // drawing // ------- @@ -818,4 +821,4 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) } #endif - // USE_OWNER_DRAWN + // wxUSE_OWNER_DRAWN