X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c4e7c2aa5822f9a6e97d8d7848b95ea2eadcd98b..5fbc0fa65aa3b6e0ea001db702817fcf68d7d327:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 074548dcc7..40f02d0f05 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -38,7 +38,7 @@ #undef GetCharWidth #endif -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif @@ -53,7 +53,7 @@ // list box item declaration and implementation // ============================================================================ -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN class wxListBoxItem : public wxOwnerDrawn { @@ -67,7 +67,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(); } @@ -149,7 +149,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_noItems = n; + m_noItems = 0; m_hWnd = 0; m_selected = 0; @@ -160,7 +160,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxSystemSettings settings; SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(parent->GetDefaultForegroundColour()); + SetForegroundColour(parent->GetForegroundColour()); m_windowId = ( id == -1 ) ? (int)NewControlId() : id; @@ -183,7 +183,7 @@ bool wxListBox::Create(wxWindow *parent, 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; @@ -198,65 +198,65 @@ bool wxListBox::Create(wxWindow *parent, 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]; } @@ -266,7 +266,7 @@ wxListBox::~wxListBox(void) void wxListBox::SetupColours(void) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(GetParent()->GetDefaultForegroundColour()); + SetForegroundColour(GetParent()->GetForegroundColour()); } void wxListBox::SetFirstItem(int N) @@ -294,9 +294,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); @@ -311,7 +311,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. @@ -337,17 +337,17 @@ void wxListBox::Set(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); @@ -484,6 +484,8 @@ void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags) 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)) { @@ -493,7 +495,7 @@ void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags) 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; @@ -538,8 +540,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 = (HFONT) ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle()); + if (GetFont().Ok() && GetFont().GetResourceHandle()) + oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); SIZE extentXY; @@ -559,8 +561,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int largestExtent = 0; HDC dc = GetWindowDC(hwnd); HFONT oldFont = 0; - if (GetFont() && GetFont()->GetResourceHandle()) - oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont()->GetResourceHandle()); + if (GetFont().Ok() && GetFont().GetResourceHandle()) + oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); int i; @@ -590,12 +592,12 @@ wxListBox::InsertItems(int nItems, const wxString items[], int pos) 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); } } @@ -626,7 +628,7 @@ void wxListBox::SetString(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); @@ -762,7 +764,7 @@ long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) return wxControl::MSWWindowProc(nMsg, wParam, lParam); } -#if USE_OWNER_DRAWN +#if wxUSE_OWNER_DRAWN // drawing // ------- @@ -816,4 +818,4 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) } #endif - // USE_OWNER_DRAWN + // wxUSE_OWNER_DRAWN