X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d44b24ee63543390aa28e1eb4ff162da4264838..19984725d5e943c8f212a80451ec1b1dc1eac8cd:/src/os2/listbox.cpp diff --git a/src/os2/listbox.cpp b/src/os2/listbox.cpp index 9fe882a4fb..aaca7eabcb 100644 --- a/src/os2/listbox.cpp +++ b/src/os2/listbox.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: listbox.cpp +// Name: src/os2/listbox.cpp // Purpose: wxListBox // Author: David Webster // Modified by: @@ -12,26 +12,28 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#include "wx/window.h" -#include "wx/os2/private.h" +#if wxUSE_LISTBOX -#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/utils.h" + +#ifndef WX_PRECOMP + #include "wx/dynarray.h" + #include "wx/settings.h" + #include "wx/brush.h" + #include "wx/font.h" + #include "wx/dc.h" + #include "wx/dcscreen.h" + #include "wx/utils.h" + #include "wx/scrolwin.h" + #include "wx/log.h" + #include "wx/window.h" #endif +#include "wx/os2/private.h" + #define INCL_M #include -#include "wx/dynarray.h" -#include "wx/log.h" - -#if wxUSE_LISTBOX - #if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif @@ -47,14 +49,14 @@ class wxListBoxItem : public wxOwnerDrawn { public: - wxListBoxItem(const wxString& rsStr = ""); + wxListBoxItem(const wxString& rsStr = wxEmptyString); }; wxListBoxItem::wxListBoxItem( const wxString& rsStr ) : wxOwnerDrawn( rsStr - ,FALSE + ,false ) { // @@ -63,9 +65,7 @@ wxListBoxItem::wxListBoxItem( SetMarginWidth(0); } // end of wxListBoxItem::wxListBoxItem -wxOwnerDrawn* wxListBox::CreateItem( - size_t n -) +wxOwnerDrawn* wxListBox::CreateItem( size_t WXUNUSED(n) ) { return new wxListBoxItem(); } // end of wxListBox::CreateItem @@ -88,14 +88,27 @@ bool wxListBox::Create( , wxWindowID vId , const wxPoint& rPos , const wxSize& rSize -, int n -, const wxString asChoices[] +, const wxArrayString& asChoices , long lStyle -#if wxUSE_VALIDATORS , const wxValidator& rValidator -#endif , const wxString& rsName ) +{ + wxCArrayString chs(asChoices); + + return Create(pParent, vId, rPos, rSize, chs.GetCount(), chs.GetStrings(), + lStyle, rValidator, rsName); +} + +bool wxListBox::Create( wxWindow* pParent, + wxWindowID vId, + const wxPoint& rPos, + const wxSize& rSize, + int n, + const wxString asChoices[], + long lStyle, + const wxValidator& rValidator, + const wxString& rsName ) { m_nNumItems = 0; m_hWnd = 0; @@ -111,7 +124,7 @@ bool wxListBox::Create( wxSystemSettings vSettings; - SetBackgroundColour(vSettings.GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetBackgroundColour(vSettings.GetColour(wxSYS_COLOUR_WINDOW)); SetForegroundColour(pParent->GetForegroundColour()); m_windowId = (vId == -1) ? (int)NewControlId() : vId; @@ -142,15 +155,6 @@ bool wxListBox::Create( // lStyle |= LS_NOADJUSTPOS; - // - // If the parent is a scrolled window the controls must - // have this style or they will overlap the scrollbars - // - if (pParent) - if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) || - pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow))) - lStyle |= WS_CLIPSIBLINGS; - m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) // Parent ,WC_LISTBOX // Default Listbox class ,"LISTBOX" // Control's name @@ -164,7 +168,7 @@ bool wxListBox::Create( ); if (m_hWnd == 0) { - return FALSE; + return false; } // @@ -178,14 +182,19 @@ bool wxListBox::Create( { Append(asChoices[lUi]); } - SetFont(pParent->GetFont()); - + wxFont* pTextFont = new wxFont( 10 + ,wxMODERN + ,wxNORMAL + ,wxNORMAL + ); + SetFont(*pTextFont); + // - // Set standard wxWindows colors for Listbox items and highlighting + // Set OS/2 system colours for Listbox items and highlighting // wxColour vColour; - vColour.Set(wxString("WHITE")); + vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); LONG lColor = (LONG)vColour.GetPixel(); @@ -194,7 +203,7 @@ bool wxListBox::Create( ,sizeof(LONG) ,(PVOID)&lColor ); - vColour.Set(wxString("NAVY")); + vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHT); lColor = (LONG)vColour.GetPixel(); ::WinSetPresParam( m_hWnd ,PP_HILITEBACKGROUNDCOLOR @@ -202,18 +211,21 @@ bool wxListBox::Create( ,(PVOID)&lColor ); + SetXComp(0); + SetYComp(0); SetSize( nX ,nY ,nWidth ,nHeight ); - return TRUE; + delete pTextFont; + return true; } // end of wxListBox::Create wxListBox::~wxListBox() { #if wxUSE_OWNER_DRAWN - size_t lUiCount = m_aItems.Count(); + size_t lUiCount = m_aItems.Count(); while (lUiCount-- != 0) { @@ -224,7 +236,7 @@ wxListBox::~wxListBox() void wxListBox::SetupColours() { - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetForegroundColour(GetParent()->GetForegroundColour()); } // end of wxListBox::SetupColours @@ -232,74 +244,67 @@ void wxListBox::SetupColours() // implementation of wxListBoxBase methods // ---------------------------------------------------------------------------- -void wxListBox::DoSetFirstItem( - int N -) +void wxListBox::DoSetFirstItem(int N) { - wxCHECK_RET( N >= 0 && N < m_nNumItems, + wxCHECK_RET( IsValid(N), wxT("invalid index in wxListBox::SetFirstItem") ); ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0); } // end of wxListBox::DoSetFirstItem -void wxListBox::Delete( - int N -) +void wxListBox::Delete(unsigned int n) { - wxCHECK_RET( N >= 0 && N < m_nNumItems, + wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") ); #if wxUSE_OWNER_DRAWN - delete m_aItems[N]; - m_aItems.RemoveAt(N); + delete m_aItems[n]; + m_aItems.RemoveAt(n); #else // !wxUSE_OWNER_DRAWN if (HasClientObjectData()) { - delete GetClientObject(N); + delete GetClientObject(n); } #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN - ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)N, (MPARAM)0); + ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0); m_nNumItems--; } // end of wxListBox::DoSetFirstItem -int wxListBox::DoAppend( - const wxString& rsItem -) +int wxListBox::DoAppend(const wxString& rsItem) { - int nIndex = 0; - SHORT nIndexType = 0; + long lIndex = 0; + LONG lIndexType = 0; if (m_windowStyle & wxLB_SORT) - nIndexType = LIT_SORTASCENDING; + lIndexType = LIT_SORTASCENDING; else - nIndexType = LIT_END; - nIndex = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)nIndexType, (MPARAM)rsItem.c_str()); + lIndexType = LIT_END; + + lIndex = (long)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)rsItem.wx_str()); m_nNumItems++; #if wxUSE_OWNER_DRAWN if (m_windowStyle & wxLB_OWNERDRAW) { - wxOwnerDrawn* pNewItem = CreateItem(nIndex); // dummy argument + wxOwnerDrawn* pNewItem = CreateItem(lIndex); // dummy argument + wxScreenDC vDc; + pNewItem->SetName(rsItem); - m_aItems.Add(pNewItem); - ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)((SHORT)nIndex), MPFROMP(pNewItem)); + m_aItems.Insert(pNewItem, lIndex); + ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem)); pNewItem->SetFont(GetFont()); } #endif - return nIndex; + return (int)lIndex; } // end of wxListBox::DoAppend -void wxListBox::DoSetItems( - const wxArrayString& raChoices -, void** ppClientData -) +void wxListBox::DoSetItems( const wxArrayString& raChoices, + void** ppClientData ) { - BOOL bHideAndShow = IsShown(); - int nCount = 0; - int i; - SHORT nIndexType = 0; + BOOL bHideAndShow = IsShown(); + LONG lIndexType = 0; if (bHideAndShow) { @@ -307,14 +312,13 @@ void wxListBox::DoSetItems( } ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0); m_nNumItems = raChoices.GetCount(); - for (i = 0; i < m_nNumItems; i++) + for (unsigned int i = 0; i < m_nNumItems; i++) { - if (m_windowStyle & wxLB_SORT) - nIndexType = LIT_SORTASCENDING; + lIndexType = LIT_SORTASCENDING; else - nIndexType = LIT_END; - ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)nIndexType, (MPARAM)raChoices[i].c_str()); + lIndexType = LIT_END; + ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].wx_str()); if (ppClientData) { @@ -333,58 +337,28 @@ void wxListBox::DoSetItems( // // First delete old items // - size_t lUi = m_aItems.Count(); - - while (lUi-- != 0) - { - delete m_aItems[lUi]; - } - m_aItems.Empty(); + WX_CLEAR_ARRAY(m_aItems); // // Then create new ones // - for (lUi = 0; lUi < (size_t)m_nNumItems; lUi++) + for (unsigned int ui = 0; ui < m_nNumItems; ui++) { - wxOwnerDrawn* pNewItem = CreateItem(lUi); + wxOwnerDrawn* pNewItem = CreateItem(ui); - pNewItem->SetName(raChoices[lUi]); + pNewItem->SetName(raChoices[ui]); m_aItems.Add(pNewItem); - ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lUi), MPFROMP(pNewItem)); + ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem)); } } #endif // wxUSE_OWNER_DRAWN ::WinShowWindow(GetHwnd(), TRUE); } // end of wxListBox::DoSetItems -int wxListBox::FindString( - const wxString& rsString -) const -{ - int nPos; - LONG lTextLength; - PSZ zStr; - - - for (nPos = 0; nPos < m_nNumItems; nPos++) - { - lTextLength = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)nPos, (MPARAM)0)); - zStr = new char[lTextLength + 1]; - ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT(nPos, (SHORT)lTextLength), (MPARAM)zStr); - if (rsString == (char*)zStr) - { - delete [] zStr; - break; - } - delete [] zStr; - } - return nPos; -} // end of wxListBox::FindString - void wxListBox::Clear() { #if wxUSE_OWNER_DRAWN - size_t lUiCount = m_aItems.Count(); + unsigned int lUiCount = m_aItems.Count(); while (lUiCount-- != 0) { @@ -395,7 +369,7 @@ void wxListBox::Clear() #else // !wxUSE_OWNER_DRAWN if (HasClientObjectData()) { - for (size_t n = 0; n < (size_t)m_lNumItems; n++) + for (unsigned int n = 0; n < m_lNumItems; n++) { delete GetClientObject(n); } @@ -406,66 +380,61 @@ void wxListBox::Clear() m_nNumItems = 0; } // end of wxListBox::Clear -void wxListBox::SetSelection( - int N -, bool bSelect -) +void wxListBox::DoSetSelection( int N, bool bSelect) { - wxCHECK_RET( N >= 0 && N < m_nNumItems, + wxCHECK_RET( IsValid(N), wxT("invalid index in wxListBox::SetSelection") ); ::WinSendMsg( GetHwnd() ,LM_SELECTITEM ,MPFROMLONG(N) ,(MPARAM)bSelect ); + if(m_windowStyle & wxLB_OWNERDRAW) + Refresh(); } // end of wxListBox::SetSelection -bool wxListBox::IsSelected( - int N -) const +bool wxListBox::IsSelected( int N ) const { - wxCHECK_MSG( N >= 0 && N < m_nNumItems, FALSE, + wxCHECK_MSG( IsValid(N), false, wxT("invalid index in wxListBox::Selected") ); LONG lItem; - lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)N, (MPARAM)0)); - return (lItem != LIT_NONE); + if (GetWindowStyleFlag() & wxLB_EXTENDED) + { + if (N == 0) + lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0)); + else + lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0)); + } + else + { + lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0)); + } + return (lItem == (LONG)N && lItem != LIT_NONE); } // end of wxListBox::IsSelected -wxClientData* wxListBox::DoGetItemClientObject( - int n -) const +wxClientData* wxListBox::DoGetItemClientObject(unsigned int n) const { return (wxClientData *)DoGetItemClientData(n); } -void* wxListBox::DoGetItemClientData( - int n -) const +void* wxListBox::DoGetItemClientData(unsigned int n) const { - wxCHECK_MSG( n >= 0 && n < m_nNumItems, NULL, + wxCHECK_MSG( IsValid(n), NULL, wxT("invalid index in wxListBox::GetClientData") ); return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0)); } // end of wxListBox::DoGetItemClientData -void wxListBox::DoSetItemClientObject( - int n -, wxClientData* pClientData -) +void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* pClientData) { - DoSetItemClientData( n - ,pClientData - ); + DoSetItemClientData(n, pClientData); } // end of wxListBox::DoSetItemClientObject -void wxListBox::DoSetItemClientData( - int n -, void* pClientData -) +void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData) { - wxCHECK_RET( n >= 0 && n < m_nNumItems, + wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetClientData") ); #if wxUSE_OWNER_DRAWN @@ -487,12 +456,10 @@ bool wxListBox::HasMultipleSelection() const return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); } // end of wxListBox::HasMultipleSelection -int wxListBox::GetSelections( - wxArrayInt& raSelections -) const +int wxListBox::GetSelections( wxArrayInt& raSelections ) const { - int nCount = 0; - LONG lItem; + int nCount = 0; + LONG lItem; raSelections.Empty(); @@ -536,7 +503,6 @@ int wxListBox::GetSelections( } return nCount; } - return 0; } else // single-selection listbox { @@ -567,109 +533,113 @@ int wxListBox::GetSelection() const )); } // end of wxListBox::GetSelection -wxString wxListBox::GetString( - int N -) const +wxString wxListBox::GetString(unsigned int n) const { - LONG lLen = 0; - char* zBuf; - wxString sResult; + LONG lLen = 0; + wxChar* zBuf; + wxString sResult; - wxCHECK_MSG( N >= 0 && N < m_nNumItems, "", + wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("invalid index in wxListBox::GetClientData") ); - lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)N, (MPARAM)0)); - zBuf = new char[lLen + 1]; - ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)N, (SHORT)lLen), (MPARAM)zBuf); + lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0)); + zBuf = new wxChar[lLen + 1]; + ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)n, (SHORT)lLen), (MPARAM)zBuf); zBuf[lLen] = '\0'; sResult = zBuf; delete [] zBuf; return sResult; } // end of wxListBox::GetString -void wxListBox::DoInsertItems( - const wxArrayString& asItems -, int nPos -) +void wxListBox::DoInsertItems(const wxArrayString& asItems, unsigned int nPos) { - wxCHECK_RET( nPos >= 0 && nPos <= m_nNumItems, + wxCHECK_RET( IsValidInsert(nPos), wxT("invalid index in wxListBox::InsertItems") ); - int nItems = asItems.GetCount(); + unsigned int nItems = asItems.GetCount(); + + for (unsigned int i = 0; i < nItems; i++) + { + int nIndex = (int)::WinSendMsg( GetHwnd(), + LM_INSERTITEM, + MPFROMLONG((LONG)(i + nPos)), + (MPARAM)asItems[i].wx_str() ); + + wxOwnerDrawn* pNewItem = CreateItem(nIndex); - for (int i = 0; i < nItems; i++) - ::WinSendMsg(GetHwnd(), LM_INSERTITEM, MPFROMLONG((LONG)(i + nPos)), (MPARAM)asItems[i].c_str()); - m_nNumItems += nItems; + pNewItem->SetName(asItems[i]); + pNewItem->SetFont(GetFont()); + m_aItems.Insert(pNewItem, nIndex); + ::WinSendMsg( GetHwnd() + ,LM_SETITEMHANDLE + ,(MPARAM)((LONG)nIndex) + ,MPFROMP(pNewItem) + ); + m_nNumItems += nItems; + } } // end of wxListBox::DoInsertItems -void wxListBox::SetString( - int N -, const wxString& rsString -) +void wxListBox::SetString(unsigned int n, const wxString& rsString) { - wxCHECK_RET( N >= 0 && N < m_nNumItems, + wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetString") ); // // Remember the state of the item // - bool bWasSelected = IsSelected(N); - void* pOldData = NULL; - wxClientData* pOldObjData = NULL; + bool bWasSelected = IsSelected(n); + void* pOldData = NULL; + wxClientData* pOldObjData = NULL; if (m_clientDataItemsType == wxClientData_Void) - pOldData = GetClientData(N); + pOldData = GetClientData(n); else if (m_clientDataItemsType == wxClientData_Object) - pOldObjData = GetClientObject(N); + pOldObjData = GetClientObject(n); // // Delete and recreate it // ::WinSendMsg( GetHwnd() ,LM_DELETEITEM - ,(MPARAM)N + ,(MPARAM)n ,(MPARAM)0 ); - int nNewN = N; + int nNewN = n; - if (N == m_nNumItems - 1) + if (n == (m_nNumItems - 1)) nNewN = -1; ::WinSendMsg( GetHwnd() ,LM_INSERTITEM ,(MPARAM)nNewN - ,(MPARAM)rsString.c_str() + ,(MPARAM)rsString.wx_str() ); // // Restore the client data // if (pOldData) - SetClientData( N - ,pOldData - ); + SetClientData(n, pOldData); else if (pOldObjData) - SetClientObject( N - ,pOldObjData - ); + SetClientObject(n, pOldObjData); // // We may have lost the selection // if (bWasSelected) - Select(N); + Select(n); #if wxUSE_OWNER_DRAWN if (m_windowStyle & wxLB_OWNERDRAW) // // Update item's text // - m_aItems[N]->SetName(rsString); + m_aItems[n]->SetName(rsString); #endif //USE_OWNER_DRAWN } // end of wxListBox::SetString -int wxListBox::GetCount() const +unsigned int wxListBox::GetCount() const { return m_nNumItems; } @@ -683,19 +653,17 @@ wxSize wxListBox::DoGetBestSize() const // // Find the widest string // - int nLine; - int nListbox = 0; - int nCx; - int nCy; + int nLine; + int nListbox = 0; + int nCx; + int nCy; + wxFont vFont = (wxFont)GetFont(); - for (int i = 0; i < m_nNumItems; i++) + for (unsigned int i = 0; i < m_nNumItems; i++) { - wxString vStr(GetString(i)); + wxString vStr(GetString(i)); - GetTextExtent( vStr - ,&nLine - ,NULL - ); + GetTextExtent( vStr, &nLine, NULL ); if (nLine > nListbox) nListbox = nLine; } @@ -713,11 +681,11 @@ wxSize wxListBox::DoGetBestSize() const wxGetCharSize( GetHWND() ,&nCx ,&nCy - ,(wxFont*)&GetFont() + ,&vFont ); nListbox += 3 * nCx; - int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7)); + int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7)); return wxSize( nListbox ,hListbox @@ -738,7 +706,7 @@ bool wxListBox::OS2Command( { eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED; } - if (uParam == LN_ENTER) + else if (uParam == LN_ENTER) { eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED; } @@ -747,7 +715,7 @@ bool wxListBox::OS2Command( // // Some event we're not interested in // - return FALSE; + return false; } wxCommandEvent vEvent( eEvtType ,m_windowId @@ -755,9 +723,9 @@ bool wxListBox::OS2Command( vEvent.SetEventObject(this); - wxArrayInt aSelections; - int n; - int nCount = GetSelections(aSelections); + wxArrayInt aSelections; + int n; + int nCount = GetSelections(aSelections); if (nCount > 0) { @@ -772,7 +740,7 @@ bool wxListBox::OS2Command( { n = -1; } - vEvent.m_commandInt = n; + vEvent.SetInt(n); return GetEventHandler()->ProcessEvent(vEvent); } // end of wxListBox::OS2Command @@ -788,22 +756,146 @@ bool wxListBox::OS2Command( // #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1) -bool wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT *item) +long wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT* pItem) { + if (!pItem) + pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM; + + POWNERITEM pMeasureStruct = (POWNERITEM)pItem; + wxScreenDC vDc; + // - // TODO: Get to this eventually + // Only owner-drawn control should receive this message // - return TRUE; -} + wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE ); + + vDc.SetFont(GetFont()); + + wxCoord vHeight; + wxCoord vWidth; + + GetSize( &vWidth + ,NULL + ); + + pMeasureStruct->rclItem.xRight = (USHORT)vWidth; + pMeasureStruct->rclItem.xLeft = 0; + pMeasureStruct->rclItem.yTop = 0; + pMeasureStruct->rclItem.yBottom = 0; -bool wxListBox::OS2OnDraw(WXDRAWITEMSTRUCT *item) + vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5); + pMeasureStruct->rclItem.yTop = (USHORT)vHeight; + + return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth)); +} // end of wxListBox::OS2OnMeasure + +bool wxListBox::OS2OnDraw ( + WXDRAWITEMSTRUCT* pItem +) { + POWNERITEM pDrawStruct = (POWNERITEM)pItem; + LONG lItemID = pDrawStruct->idItem; + int eAction = 0; + int eStatus = 0; + // - // TODO: Get to this eventually + // Only owner-drawn control should receive this message // - return FALSE; -} -#endif // ndef for wxUSE_OWNER_DRAWN + wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false); + + + // + // The item may be -1 for an empty listbox + // + if (lItemID == -1L) + return false; + + wxListBoxItem* pData = (wxListBoxItem*)PVOIDFROMMR( ::WinSendMsg( GetHwnd() + ,LM_QUERYITEMHANDLE + ,MPFROMLONG(pDrawStruct->idItem) + ,(MPARAM)0 + ) + ); + + wxCHECK(pData, false ); + + wxDC vDc; + wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop ); + wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom ); + wxRect vRect( pt1, pt2 ); -#endif // ndef for wxUSE_LISTBOX + vDc.SetHPS(pDrawStruct->hps); + + if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld) + { + // + // Entire Item needs to be redrawn (either it has reappeared from + // behind another window or is being displayed for the first time + // + eAction = wxOwnerDrawn::wxODDrawAll; + + if (pDrawStruct->fsAttribute & MIA_HILITED) + { + // + // If it is currently selected we let the system handle it + // + eStatus |= wxOwnerDrawn::wxODSelected; + } + if (pDrawStruct->fsAttribute & MIA_CHECKED) + { + // + // If it is currently checked we draw our own + // + eStatus |= wxOwnerDrawn::wxODChecked; + pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED; + } + if (pDrawStruct->fsAttribute & MIA_DISABLED) + { + // + // If it is currently disabled we let the system handle it + // + eStatus |= wxOwnerDrawn::wxODDisabled; + } + // + // Don't really care about framed (indicationg focus) or NoDismiss + // + } + else + { + if (pDrawStruct->fsAttribute & MIA_HILITED) + { + eAction = wxOwnerDrawn::wxODDrawAll; + eStatus |= wxOwnerDrawn::wxODSelected; + // + // Keep the system from trying to highlight with its bogus colors + // + pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED; + } + else if (!(pDrawStruct->fsAttribute & MIA_HILITED)) + { + eAction = wxOwnerDrawn::wxODDrawAll; + eStatus = 0; + // + // Keep the system from trying to highlight with its bogus colors + // + pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED; + } + else + { + // + // For now we don't care about anything else + // just ignore the entire message! + // + return true; + } + } + return pData->OnDrawItem( vDc + ,vRect + ,(wxOwnerDrawn::wxODAction)eAction + ,(wxOwnerDrawn::wxODStatus)eStatus + ); +} // end of wxListBox::OS2OnDraw + +#endif // ndef for wxUSE_OWNER_DRAWN +#endif // wxUSE_LISTBOX