+/////////////////////////////////////////////////////////////////////////////
+//
+// InternalDataCompareFunc
+//
+// This is compare function we pass to PM. It wraps the real compare
+// function in SInternalDataSort
+//
+// PARAMETERS
+// p1 -- is the first record structure to compare
+// p2 -- is the second record structure to compare
+// lStorage -- is the same value as passed to SortItems.
+//
+// RETURN VALUE
+// pointer to the internal data attribute
+//
+/////////////////////////////////////////////////////////////////////////////
+SHORT EXPENTRY InternalDataCompareFunc (
+ PMYRECORD p1
+, PMYRECORD p2
+, PVOID pStorage
+)
+{
+ SInternalDataSort* pInternalData = (SInternalDataSort *)pStorage;
+ CListItemInternalData* pData1 = (CListItemInternalData *)p1->m_ulUserData;
+ CListItemInternalData* pData2 = (CListItemInternalData *)p2->m_ulUserData;
+ long lD1 = (pData1 == NULL ? 0 : (long)pData1->m_lParam);
+ long lD2 = (pData2 == NULL ? 0 : (long)pData2->m_lParam);
+
+ return(pInternalData->m_fnUser( lD1
+ ,lD2
+ ,pInternalData->m_lData
+ ));
+} // end of InternalDataCompareFunc
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// ConvertFromOS2ListItem
+//
+// Convert from an internal PM List item to a Toolkit List item
+//
+// PARAMETERS
+// hWndListCtrl -- the control's windows handle
+// rInfo -- the library list control to convert to
+// pRecord -- the OS list control to convert from
+//
+// RETURN VALUE
+// none
+//
+/////////////////////////////////////////////////////////////////////////////
+void ConvertFromOS2ListItem ( HWND hWndListCtrl,
+ wxListItem& rInfo,
+ PMYRECORD pRecord )
+{
+ CListItemInternalData* pInternaldata = (CListItemInternalData *)pRecord->m_ulUserData;
+ bool bNeedText = false;
+
+ if (pInternaldata)
+ rInfo.SetData(pInternaldata->m_lParam);
+
+ rInfo.SetMask(0);
+ rInfo.SetState(0);
+ rInfo.SetStateMask(0);
+ rInfo.SetId((long)pRecord->m_ulItemId);
+ if (hWndListCtrl != 0)
+ {
+ pRecord = FindOS2ListRecordByID( hWndListCtrl
+ ,rInfo.GetId()
+ );
+ }
+
+ //
+ // The wxListItem class is really set up to handle the WIN32 list item
+ // and OS/2 are not as complicated. Just set both state members to the
+ // same thing under OS/2
+ //
+ if (pRecord->m_vRecord.flRecordAttr & CRA_DROPONABLE)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_DROPHILITED);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_DROPHILITED);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_SELECTED)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_SELECTED);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_SELECTED);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_DISABLED)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_DISABLED);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_DISABLED);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_FILTERED)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_FILTERED);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_FILTERED);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_INUSE)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_INUSE);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_INUSE);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_PICKED)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_PICKED);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_PICKED);
+ }
+ if (pRecord->m_vRecord.flRecordAttr & CRA_SOURCE)
+ {
+ rInfo.SetStateMask(rInfo.m_stateMask | wxLIST_STATE_SOURCE);
+ rInfo.SetState(rInfo.m_state | wxLIST_STATE_SOURCE);
+ }
+
+ if (pRecord->m_vRecord.pszText != (PSZ)NULL)
+ {
+ rInfo.SetMask(rInfo.GetMask() | wxLIST_MASK_TEXT);
+ rInfo.SetText(pRecord->m_vRecord.pszText);
+ }
+ if (pRecord->m_vRecord.pszIcon != (PSZ)NULL ||
+ pRecord->m_vRecord.pszName != (PSZ)NULL)
+ {
+ rInfo.SetMask(rInfo.GetMask() | wxLIST_MASK_IMAGE);
+ rInfo.SetImage(pRecord->m_vRecord.hptrIcon);
+ }
+ if (pRecord->m_ulUserData)
+ rInfo.SetMask(rInfo.GetMask() | wxLIST_MASK_DATA);
+} // end of ConvertFromOS2ListItem
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// ConvertToOS2Flags
+//
+// Convert from an library states to OS states
+//
+// PARAMETERS
+// lState -- the state
+// pRecord -- the OS list control to use
+//
+// RETURN VALUE
+// none
+//
+/////////////////////////////////////////////////////////////////////////////
+void ConvertToOS2Flags (
+ long lState
+, PMYRECORD pRecord
+)
+{
+ if (lState & wxLIST_STATE_DROPHILITED)
+ pRecord->m_vRecord.flRecordAttr |= CRA_DROPONABLE;
+ if (lState & wxLIST_STATE_SELECTED)
+ pRecord->m_vRecord.flRecordAttr |= CRA_SELECTED;
+ if (lState & wxLIST_STATE_DISABLED)
+ pRecord->m_vRecord.flRecordAttr |= CRA_DISABLED;
+ if (lState & wxLIST_STATE_FILTERED)
+ pRecord->m_vRecord.flRecordAttr |= CRA_FILTERED;
+ if (lState & wxLIST_STATE_INUSE)
+ pRecord->m_vRecord.flRecordAttr |= CRA_INUSE;
+ if (lState & wxLIST_STATE_PICKED)
+ pRecord->m_vRecord.flRecordAttr |= CRA_PICKED;
+ if (lState & wxLIST_STATE_SOURCE)
+ pRecord->m_vRecord.flRecordAttr |= CRA_SOURCE;
+} // end of ConvertToOS2Flags
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// ConvertToOS2ListItem
+//
+// Convert from a library List item to an internal OS2 List item. We set
+// only the fields we need to set. Some of them are set by the API when
+// they are added to the container.
+//
+// PARAMETERS
+// pCtrl -- the control to use
+// rInfo -- the item to convert
+// pRecord -- the OS list control to use, should be zeroed out
+// pFieldinfo -- a field struct that may contain columnar data for detail view
+//
+// RETURN VALUE
+// none
+//
+/////////////////////////////////////////////////////////////////////////////
+void ConvertToOS2ListItem (
+ const wxListCtrl* pCtrl
+, const wxListItem& rInfo
+, PMYRECORD pRecord
+, PFIELDINFO pFieldInfo
+)
+{
+ pRecord->m_ulItemId = (ULONG)rInfo.GetId();
+ pRecord->m_vRecord.cb = sizeof(RECORDCORE);
+ if (rInfo.GetMask() & wxLIST_MASK_STATE)
+ {
+ ConvertToOS2Flags( rInfo.m_state
+ ,pRecord
+ );
+ }
+ if (pCtrl->GetWindowStyleFlag() & wxLC_ICON ||
+ pCtrl->GetWindowStyleFlag() & wxLC_SMALL_ICON)
+ {
+ pRecord->m_vRecord.pszIcon = (char*)rInfo.GetText().c_str();
+ }
+ if (pCtrl->GetWindowStyleFlag() & wxLC_LIST) // PM TEXT view
+ {
+ pRecord->m_vRecord.pszText = (char*)rInfo.GetText().c_str();
+ }
+ //
+ // In the case of a report view the text will be the data in the lead column
+ // ???? Don't know why, but that is how it works in other ports.
+ //
+ if (pCtrl->GetWindowStyleFlag() & wxLC_REPORT)
+ {
+ if (pFieldInfo)
+ {
+ switch(rInfo.GetColumn())
+ {
+ case 0:
+ pRecord->m_pzColumn1 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn1);
+ break;
+
+ case 1:
+ pRecord->m_pzColumn2 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn2);
+ break;
+
+ case 2:
+ pRecord->m_pzColumn3 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn3);
+ break;
+
+ case 3:
+ pRecord->m_pzColumn4 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn4);
+ break;
+
+ case 4:
+ pRecord->m_pzColumn5 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn5);
+ break;
+
+ case 5:
+ pRecord->m_pzColumn6 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn6);
+ break;
+
+ case 6:
+ pRecord->m_pzColumn7 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn7);
+ break;
+
+ case 7:
+ pRecord->m_pzColumn8 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn8);
+ break;
+
+ case 8:
+ pRecord->m_pzColumn9 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn9);
+ break;
+
+ case 9:
+ pRecord->m_pzColumn10 = (char*)rInfo.GetText().c_str();
+ pFieldInfo->offStruct = FIELDOFFSET(MYRECORD, m_pzColumn10);
+ break;
+
+ default:
+ wxFAIL_MSG( _T("wxOS2 does not support more than 10 columns in REPORT view") );
+ break;
+ }
+ }
+ }
+ if (rInfo.GetMask() & wxLIST_MASK_IMAGE)
+ {
+ pRecord->m_vRecord.hptrIcon = (HPOINTER)rInfo.GetImage();
+ pRecord->m_vRecord.hptrMiniIcon = (HPOINTER)rInfo.m_miniImage;
+ }
+} // end of ConvertToOS2ListItem
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// ConvertToOS2ListCol
+//
+// Convert from a library List column to an internal PM List column
+//
+// PARAMETERS
+// lCol -- the columnd to convert
+// rItem -- the item to convert
+// pField -- the OS list column to use
+//
+// RETURN VALUE
+// none
+//
+/////////////////////////////////////////////////////////////////////////////
+void ConvertToOS2ListCol (
+ long lCol
+, const wxListItem& rItem
+, PFIELDINFO pField
+)
+{
+ memset(pField, '\0', sizeof(FIELDINFO));
+ pField->cb = sizeof(FIELDINFO);
+
+ //
+ // Default some settings
+ //
+ pField->flData = CFA_HORZSEPARATOR | CFA_SEPARATOR;
+ pField->flTitle = CFA_CENTER;
+
+ if (rItem.GetMask() & wxLIST_MASK_TEXT)
+ {
+ pField->flData |= CFA_STRING;
+ pField->pTitleData = (PVOID)rItem.GetText().c_str(); // text is column title not data
+ }
+ if (rItem.GetMask() & wxLIST_MASK_FORMAT)
+ {
+ if (rItem.m_format == wxLIST_FORMAT_LEFT)
+ pField->flData |= CFA_LEFT;
+ else if (rItem.m_format == wxLIST_FORMAT_RIGHT)
+ pField->flData |= CFA_RIGHT;
+ else if (rItem.m_format == wxLIST_FORMAT_CENTRE)
+ pField->flData |= CFA_CENTER;
+ }
+ else
+ pField->flData |= CFA_CENTER; // Just ensure the default is centered
+ if (rItem.GetMask() & wxLIST_MASK_WIDTH)
+ {
+ if (!(rItem.GetWidth() == wxLIST_AUTOSIZE ||
+ rItem.GetWidth() == wxLIST_AUTOSIZE_USEHEADER))
+ pField->cxWidth = rItem.GetWidth();
+ // else: OS/2 automatically sets the width if created with the approppriate style
+ }
+
+ //
+ // Still need to set the actual data
+ //
+ pField->offStruct = 0;
+} // end of ConvertToOS2ListCol
+
+
+IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
+IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
+
+IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
+
+BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
+ EVT_PAINT(wxListCtrl::OnPaint)
+END_EVENT_TABLE()
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxListCtrl construction
+// ----------------------------------------------------------------------------
+
+void wxListCtrl::Init ()
+{
+ m_pImageListNormal = NULL;
+ m_pImageListSmall = NULL;
+ m_pImageListState = NULL;
+ m_bOwnsImageListNormal = false;
+ m_bOwnsImageListSmall = false;
+ m_bOwnsImageListState = false;
+ m_lBaseStyle = 0L;
+ m_nColCount = 0;
+ m_pTextCtrl = NULL;
+ m_bAnyInternalData = false;
+ m_bHasAnyAttr = false;
+} // end of wxListCtrl::Init
+
+bool wxListCtrl::Create ( wxWindow* pParent,
+ wxWindowID vId,
+ const wxPoint& rPos,
+ const wxSize& rSize,
+ long lStyle,
+ const wxValidator& rValidator,
+ const wxString& rsName )
+{
+ int nX = rPos.x;
+ int nY = rPos.y;
+ int nWidth = rSize.x;
+ int nHeight = rSize.y;
+
+#if wxUSE_VALIDATORS
+ SetValidator(rValidator);
+#endif // wxUSE_VALIDATORS
+
+ SetName(rsName);
+ SetWindowStyleFlag(lStyle);
+ SetParent(pParent);
+ if (nWidth <= 0)
+ nWidth = 100;
+ if (nHeight <= 0)
+ nHeight = 30;
+ if (nX < 0)
+ nX = 0;
+ if (nY < 0)
+ nY = 0;
+
+ m_windowId = (vId == -1) ? NewControlId() : vId;
+
+ long lSstyle = WS_VISIBLE | WS_TABSTOP;
+
+ if (GetWindowStyleFlag() & wxCLIP_SIBLINGS)
+ lSstyle |= WS_CLIPSIBLINGS;
+ m_lBaseStyle = lSstyle;
+ if (!DoCreateControl( nX
+ ,nY
+ ,nWidth
+ ,nHeight
+ ))
+ return false;
+ if (pParent)
+ pParent->AddChild(this);
+ return true;
+} // end of wxListCtrl::Create
+
+bool wxListCtrl::DoCreateControl ( int nX, int nY,
+ int nWidth, int nHeight )
+{
+ DWORD lWstyle = m_lBaseStyle;
+ long lOldStyle = 0; // Dummy
+
+ CNRINFO vCnrInfo;
+
+ lWstyle |= ConvertToOS2Style( lOldStyle
+ ,GetWindowStyleFlag()
+ );
+
+ m_hWnd = (WXHWND)::WinCreateWindow( GetParent()->GetHWND()
+ ,WC_CONTAINER
+ ,NULL
+ ,m_lBaseStyle
+ ,0, 0, 0, 0
+ ,GetParent()->GetHWND()
+ ,HWND_BOTTOM
+ ,(ULONG)m_windowId
+ ,NULL
+ ,NULL
+ );
+ if (!m_hWnd)
+ {
+ return false;
+ }