使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 0408576e9da10015ffa9da0079b8c985113ce4b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 
#pragma once
 
#include <helper/SAdapterBase.h>
 
struct IObjectAdapterCallback
{
    virtual void OnClickCBItem(CString strCtrlName,int nIndex,CString strText) = 0;
};
 
class CObjectAdapter : public SAdapterBase
{
public:
    struct SAdapterObject
    {
        SStringT strText; 
        SStringT strData; 
        DWORD    dwData;
        SAdapterObject(){dwData=0 ;}
    };
private:
    SArray<SAdapterObject> m_arrObject;
    IObjectAdapterCallback* m_pCBCallback;
    CString        m_strCtrlName;        
public:
    CObjectAdapter(IObjectAdapterCallback* pCBCallback){
        m_pCBCallback = pCBCallback;
    }
    ~CObjectAdapter(){}
 
    virtual int getCount()
    {
        return m_arrObject.GetCount();
    }
 
    virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
    {
        if (pItem->GetChildrenCount() == 0)
            pItem->InitFromXml(xmlTemplate);
 
        SWindow* pWnd = pItem->FindChildByID(1);
        SStringT strText = getItemText(position);
        pWnd->SetWindowText(strText);
 
        pItem->SetUserData(position);
        pItem->GetEventSet()->subscribeEvent(EventItemPanelClick::EventID, Subscriber(&CObjectAdapter::OnItemClick, this));
    }
 
    bool OnItemClick(EventArgs *pEvt)
    {
        EventItemPanelClick* pEvt_ItemPanel = sobj_cast<EventItemPanelClick>(pEvt);
        SASSERT(pEvt_ItemPanel);
        SWindow* pPanel = sobj_cast<SWindow>(pEvt_ItemPanel->sender);
        SOUI::CPoint pt(GET_X_LPARAM(pEvt_ItemPanel->lParam), GET_Y_LPARAM(pEvt_ItemPanel->lParam));
        SWND swnd = pPanel->SwndFromPoint(pt, FALSE);
        SWindow *pClicked = NULL;
        if (swnd)
        {
            pClicked = SWindowMgr::GetWindow(swnd);
        }
 
        int nIndex = pPanel->GetUserData();
        CString strText = getItemText(nIndex);
        m_pCBCallback->OnClickCBItem(m_strCtrlName,nIndex,strText);
 
        return true;
    }
    SStringT getItemDesc(int position)
    {
        SASSERT(position >= 0 && position < (int)m_arrObject.GetCount());
        return m_arrObject[position].strText;
    }
    SStringT getItemText(int position)
    {
        SASSERT(position >= 0 && position < (int)m_arrObject.GetCount());
        return m_arrObject[position].strText;
    }
    SStringT getItemStrData(int position)
    {
        SASSERT(position >= 0 && position < (int)m_arrObject.GetCount());
        return m_arrObject[position].strData;
    }
    DWORD getItemData(int position)
    {
        SASSERT(position >= 0 && position < (int)m_arrObject.GetCount());
        return m_arrObject[position].dwData;
    }
    SAdapterObject getItem(int position)
    {
        SASSERT(position >= 0 && position < (int)m_arrObject.GetCount());
        return m_arrObject[position];
    }
    void SetCtrlName(const SStringT& strText)
    {
        m_strCtrlName = strText;
    }
    void AddText(const SStringT& strText)
    {
        SAdapterObject  itemObject ;
        itemObject.strData = strText;
        itemObject.strText = strText;
        itemObject.dwData = 0;
        m_arrObject.Add(itemObject);
        notifyDataSetChanged();
    }
    void AddObject(const SStringT& strText,const SStringT& strData,DWORD dwData = 0)
    {
        SAdapterObject  itemObject ;
        itemObject.strData = strData;
        itemObject.strText = strText;
        itemObject.dwData = dwData;
        m_arrObject.Add(itemObject);
        notifyDataSetChanged();
    }
    void Clear()
    {
        m_arrObject.RemoveAll();
        this->notifyDataSetChanged();
    }
    int GetTextIndex(CString strText)
    {
        CString strTempText ;
        strText.Trim();
        int nIndex = -1;
        for(int i =0; i < m_arrObject.GetCount(); i++)
        {
            SAdapterObject  itemObject = m_arrObject.GetAt(i);
            strTempText = itemObject.strText;
            strTempText.Trim();
            if(strText == strTempText)
            {
                nIndex = i;
                break;
            }
        }
        return nIndex;
    }
    int GetDataIndex(CString strData)
    {
        CString strTempData ;
        strData.Trim();
        int nIndex = -1;
        for(int i =0; i < m_arrObject.GetCount(); i++)
        {
            SAdapterObject  itemObject = m_arrObject.GetAt(i);
            strTempData = itemObject.strData;
            strTempData.Trim();
            if(strData == strTempData)
            {
                nIndex = i;
                break;
            }
        }
        return nIndex;
    }
};