soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SComboView.cpp
1#include "souistd.h"
2#include "control/SComboView.h"
3
4SNSBEGIN
6 : m_pListBox(NULL)
7{
8}
9
11{
12 if (m_pListBox)
13 {
14 m_pListBox->SetOwner(NULL);
15 m_pListBox->SSendMessage(WM_DESTROY);
16 m_pListBox->Release();
17 }
18}
19
21{
22 SASSERT(xmlNode);
23 //创建列表控件
24 SXmlNode listStyle = xmlNode.child(L"listStyle");
25 SStringW strListClass = listStyle.attribute(L"wndclass").as_string(SListView::GetClassName());
26 SListView *pListBox = sobj_cast<SListView>(CreateChildByName(strListClass));
27 if (!pListBox)
28 return FALSE;
29 m_pListBox = pListBox;
30
31 m_pListBox->SetContainer(GetContainer());
32
33 m_pListBox->InitFromXml(&listStyle);
34 m_pListBox->SetAttribute(L"pos", L"0,0,-0,-0", TRUE);
35 m_pListBox->SetAttribute(L"hotTrack", L"1", TRUE);
36 m_pListBox->SetOwner(this); // chain notify message to combobox
37 m_pListBox->SetVisible(FALSE);
38 m_pListBox->SetID(IDC_DROPDOWN_LIST);
39
40 return TRUE;
41}
42
44{
45 int nDropHeight = m_nDropHeight.toPixelSize(GetScale());
46 if (GetCount())
47 {
48 IListViewItemLocator *pItemLocator = m_pListBox->GetItemLocator();
49 SASSERT(pItemLocator);
50 CRect rcMargin = m_pListBox->GetStyle().GetMargin();
51 nDropHeight = smin(nDropHeight, (int)(pItemLocator->GetTotalHeight() + rcMargin.top + rcMargin.bottom));
52 }
53 return nDropHeight;
54}
55
57{
58 __baseCls::OnCreateDropDown(pDropDown);
59 pDropDown->GetRoot()->InsertChild(m_pListBox);
60 pDropDown->GetRoot()->UpdateChildrenPosition();
61
62 m_pListBox->SetVisible(TRUE);
63 m_pListBox->SetFocus();
64 m_pListBox->EnsureVisible(GetCurSel());
65}
66
68{
69 pDropDown->GetRoot()->RemoveChild(m_pListBox);
70 m_pListBox->SetVisible(FALSE);
71 m_pListBox->SetContainer(GetContainer());
72 __baseCls::OnDestroyDropDown(pDropDown);
73}
74
76{
77 m_pListBox->GetSel();
78 if (m_pEdit && !m_pEdit->GetEventSet()->isMuted())
79 {
80 SStringT strText = GetLBText(m_pListBox->GetSel(), FALSE);
81 m_pEdit->GetEventSet()->setMutedState(true);
82 SComboBase::SetWindowText(strText);
83 m_pEdit->GetEventSet()->setMutedState(false);
84 }
85 Invalidate();
86 __baseCls::OnSelChanged();
87}
88
89BOOL SComboView::FireEvent(IEvtArgs *evt)
90{
91 if (evt->IdFrom() == IDC_DROPDOWN_LIST && m_pDropDownWnd)
92 {
93 if (evt->GetID() == EventLVSelChanged::EventID)
94 {
96 return TRUE;
97 }
98 if (evt->GetID() == EventCmd::EventID)
99 {
100 CloseUp();
101 return TRUE;
102 }
103 }
104 return SComboBase::FireEvent(evt);
105}
106
108{
109 __baseCls::OnScaleChanged(nScale);
110 if (m_pListBox)
111 m_pListBox->SSendMessage(UM_SETSCALE, GetScale());
112}
113
115{
116 return m_pListBox;
117}
118
119BOOL SComboView::GetItemText(int iItem, BOOL bRawText, IStringT *str) const
120{
121 ILvAdapter *pAdapter = m_pListBox->GetAdapter();
122 if (!pAdapter || iItem == -1)
123 return FALSE;
124 SStringW strDesc;
125 pAdapter->getItemDesc(iItem, &strDesc);
126 if (!bRawText)
127 strDesc = tr(strDesc);
128 SStringT ret = S_CW2T(strDesc);
129 str->Copy(&ret);
130 return TRUE;
131}
132
134{
135 ILvAdapter *pAdapter = m_pListBox->GetAdapter();
136 if (!pAdapter)
137 return 0;
138 return pAdapter->getCount();
139}
140
142{
143 return m_pListBox->GetSel();
144}
145
147{
148 if (m_pListBox->GetSel() == iSel)
149 return FALSE;
150 m_pListBox->SetSel(iSel);
151 OnSelChanged();
152 return TRUE;
153}
154
156{
157 HRESULT hr = __baseCls::OnLanguageChanged();
158 if (m_pListBox)
159 m_pListBox->SSendMessage(UM_SETLANGUAGE);
160 return hr;
161}
162
164{
165 return GetListView();
166}
167
168SNSEND
BOOL GetItemText(int iItem, BOOL bRawText, IStringT *str) SCONST OVERRIDE
Get the text of a list view item.
virtual void OnSelChanged()
Handle selection change in the dropdown window.
virtual int GetListBoxHeight()
Get the height of the list view.
virtual void OnDestroyDropDown(SDropDownWnd *pDropDown)
Handle destruction of the dropdown window.
virtual void OnCreateDropDown(SDropDownWnd *pDropDown)
Handle creation of the dropdown window.
SListView * m_pListBox
Definition SComboView.h:138
IListView * GetIListView() OVERRIDE
Get the list view interface.
virtual void OnScaleChanged(int nScale)
Handle scale change event.
virtual BOOL CreateListBox(SXmlNode xmlNode)
Create the list view.
BOOL SetCurSel(int iSel) OVERRIDE
Set the current selection index.
~SComboView(void)
Destructor.
int GetCount() SCONST OVERRIDE
Get the number of items in the list view.
int GetCurSel() SCONST OVERRIDE
Get the current selection index.
SComboView(void)
Constructor.
Definition SComboView.cpp:5
SListView * GetListView()
Get the list view pointer.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Notify event.
virtual HRESULT OnLanguageChanged() override
Handle language change event.
Dropdown Window Class.
Definition SDropDown.h:43
SWindow * GetRoot() const
Gets the root window.
Definition SHostWnd.h:685
static LPCWSTR GetClassName()
Definition Sobject.hpp:41
A class representing an ASCII string.
Definition sstringw.h:96
BOOL RemoveChild(SWindow *pChild)
Removes a child window from the window tree.
Definition Swnd.cpp:602
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
Definition Swnd.cpp:3266
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
Definition Swnd.cpp:679
void InsertChild(SWindow *pNewChild, SWindow *pInsertAfter=NULL)
Inserts a child window into the window tree.
Definition Swnd.cpp:538
virtual SStringW tr(const SStringW &strSrc) const
Translation function.
Definition Swnd.cpp:940
void UpdateChildrenPosition() OVERRIDE
Updates the position of child windows.
Definition Swnd.cpp:2189
virtual SWindow * CreateChildByName(LPCWSTR pszName)
Create child window by name.
Definition Swnd.cpp:935
void Invalidate() OVERRIDE
Invalidates the entire window.
Definition Swnd.cpp:1437
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
Definition SXml.cpp:95
Class representing an XML node.
Definition SXml.h:352
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
Definition SXml.cpp:428
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
Definition SXml.cpp:423