soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SComboBox.cpp
1#include "souistd.h"
2#include "control/SComboBox.h"
3
4SNSBEGIN
5
6//////////////////////////////////////////////////////////////////////////
11
13{
14 if (m_pListBox)
15 {
16 m_pListBox->SetOwner(NULL);
17 m_pListBox->SSendMessage(WM_DESTROY);
18 m_pListBox->Release();
19 }
20}
21
23{
24 if (!xmlNode)
25 return FALSE;
26 //创建列表控件
27 SXmlNode listStyle = xmlNode.child(L"listStyle");
28 SStringW strListClass = listStyle.attribute(L"wndclass").as_string(SListBox::GetClassName());
29 SListBox *pListBox = sobj_cast<SListBox>(CreateChildByName(strListClass));
30 if (!pListBox)
31 return FALSE;
32 m_pListBox = pListBox;
33
34 m_pListBox->SetContainer(GetContainer());
35 m_pListBox->InitFromXml(&listStyle);
36 m_pListBox->SetAttribute(L"pos", L"0,0,-0,-0", TRUE);
37 m_pListBox->SetAttribute(L"hotTrack", L"1", TRUE);
38 m_pListBox->SetOwner(this); // chain notify message to combobox
39 m_pListBox->SetVisible(FALSE);
40 m_pListBox->SetID(IDC_DROPDOWN_LIST);
41 m_pListBox->SSendMessage(UM_SETSCALE, GetScale());
42
43 //初始化列表数据
44 SXmlNode xmlNode_Items = xmlNode.child(L"items");
45 if (xmlNode_Items)
46 {
47 SXmlNode xmlNode_Item = xmlNode_Items.child(L"item");
48 while (xmlNode_Item)
49 {
50
51 SStringW strText = xmlNode_Item.attribute(L"text").value();
52 if (strText.IsEmpty())
53 strText = GetXmlText(xmlNode_Item);
54 int iIcon = xmlNode_Item.attribute(L"icon").as_int(0);
55 LPARAM lParam = xmlNode_Item.attribute(L"data").as_int(0);
56 m_pListBox->AddString(S_CW2T(GETSTRING(strText)), iIcon, lParam);
57 xmlNode_Item = xmlNode_Item.next_sibling(L"item");
58 }
59 }
60
61 if (m_iInitSel != -1)
62 {
63 SetCurSel(m_iInitSel);
64 }
65 return TRUE;
66}
67
69{
70 int nDropHeight = m_nDropHeight.toPixelSize(GetScale());
71 if (GetCount())
72 {
73 int nItemHeight = m_pListBox->GetItemHeight();
74 CRect rcMargin = m_pListBox->GetStyle().GetMargin();
75 nDropHeight = smin(nDropHeight, (int)(nItemHeight * GetCount() + rcMargin.top + rcMargin.bottom));
76 }
77 return nDropHeight;
78}
79
81{
82 __baseCls::OnCreateDropDown(pDropDown);
83 pDropDown->GetRoot()->InsertChild(m_pListBox);
84 pDropDown->GetRoot()->UpdateChildrenPosition();
85 pDropDown->GetRoot()->SDispatchMessage(UM_SETSCALE, GetScale(), 0);
86 pDropDown->GetRoot()->SDispatchMessage(UM_SETCOLORIZE, m_crColorize, 0);
87
88 m_pListBox->SetVisible(TRUE);
89 m_pListBox->SetFocus();
90 m_pListBox->EnsureVisible(GetCurSel());
91}
92
94{
95 pDropDown->GetRoot()->RemoveChild(m_pListBox);
96 m_pListBox->SetVisible(FALSE);
97 m_pListBox->SetContainer(GetContainer());
98 __baseCls::OnDestroyDropDown(pDropDown);
99}
100
102{
103 m_pListBox->GetCurSel();
104 if (m_pEdit && !m_pEdit->GetEventSet()->isMuted())
105 {
106 SStringT strText = GetLBText(m_pListBox->GetCurSel());
107 m_pEdit->GetEventSet()->setMutedState(true);
108 SComboBase::SetWindowText(strText);
109 m_pEdit->GetEventSet()->setMutedState(false);
110 }
111 Invalidate();
112 __baseCls::OnSelChanged();
113}
114
115BOOL SComboBox::FireEvent(IEvtArgs *evt)
116{
117 if (evt->IdFrom() == IDC_DROPDOWN_LIST && m_pDropDownWnd)
118 {
119 if (evt->GetID() == EventLBSelChanged::EventID)
120 {
121 OnSelChanged();
122 return TRUE;
123 }
124 if (evt->GetID() == EventCmd::EventID)
125 {
126 CloseUp();
127 return TRUE;
128 }
129 }
130 return SComboBase::FireEvent(evt);
131}
132
134{
135 __baseCls::OnScaleChanged(nScale);
136 if (m_pListBox)
137 m_pListBox->SSendMessage(UM_SETSCALE, GetScale());
138}
139
141{
142 HRESULT hr = __baseCls::OnLanguageChanged();
143 if (m_pListBox)
144 m_pListBox->SSendMessage(UM_SETLANGUAGE);
145 return hr;
146}
147
149{
150 if (m_pListBox->SetCurSel(iSel))
151 {
152 m_pListBox->EnsureVisible(iSel);
153 OnSelChanged();
154 return TRUE;
155 }
156 else
157 {
158 return FALSE;
159 }
160}
161
163{
164 return m_pListBox->GetCurSel();
165}
166
168{
169 return m_pListBox->GetCount();
170}
171
172LPARAM SComboBox::GetItemData(UINT iItem) const
173{
174 return m_pListBox->GetItemData(iItem);
175}
176
177BOOL SComboBox::SetItemData(UINT iItem, LPARAM lParam)
178{
179 return m_pListBox->SetItemData(iItem, lParam);
180}
181
182int SComboBox::InsertItem(int iPos, LPCTSTR pszText, int iIcon, LPARAM lParam)
183{
184 return m_pListBox->InsertString(iPos, pszText, iIcon, lParam);
185}
186
188{
189 return m_pListBox->DeleteString(iPos);
190}
191
193{
194 SetCurSel(-1);
195 return m_pListBox->DeleteAll();
196}
197
198BOOL SComboBox::GetItemText(int iItem, BOOL bRawText, IStringT *str) const
199{
200 if (iItem < 0 || iItem >= GetCount())
201 return FALSE;
202
203 SStringT strRet = m_pListBox->GetText(iItem, bRawText);
204 str->Copy(&strRet);
205 return TRUE;
206}
207
209{
210 return GetListBox();
211}
212
213SNSEND
int GetCurSel() SCONST OVERRIDE
Get the current selection index.
LPARAM GetItemData(UINT iItem) SCONST OVERRIDE
Get the data associated with a list box item.
int InsertItem(int iPos, LPCTSTR pszText, int iIcon, LPARAM lParam) OVERRIDE
Insert an item into the list box.
virtual void OnSelChanged()
Handle selection change in the dropdown window.
SComboBox()
Constructor.
Definition SComboBox.cpp:7
virtual void OnCreateDropDown(SDropDownWnd *pDropDown)
Handle creation of the dropdown window.
Definition SComboBox.cpp:80
SListBox * GetListBox()
Get the list box pointer.
Definition SComboBox.h:136
BOOL GetItemText(int iItem, BOOL bRawText, IStringT *str) SCONST OVERRIDE
Get the text of a list box item.
virtual void OnScaleChanged(int nScale)
Handle scale change event.
SListBox * m_pListBox
Definition SComboBox.h:193
virtual int GetListBoxHeight()
Get the height of the list box.
Definition SComboBox.cpp:68
void ResetContent() OVERRIDE
Reset the content of the list box.
virtual void OnDestroyDropDown(SDropDownWnd *pDropDown)
Handle destruction of the dropdown window.
Definition SComboBox.cpp:93
virtual HRESULT OnLanguageChanged()
Handle language change event.
BOOL SetItemData(UINT iItem, LPARAM lParam) OVERRIDE
Set the data associated with a list box item.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Notify event.
BOOL DeleteString(int iPos) OVERRIDE
Delete a string from the list box.
IListBox * GetIListBox() OVERRIDE
Get the list box interface.
BOOL SetCurSel(int iSel) OVERRIDE
Set the current selection index.
virtual ~SComboBox()
Destructor.
Definition SComboBox.cpp:12
virtual BOOL CreateListBox(SXmlNode xmlNode)
Create the list box.
Definition SComboBox.cpp:22
int GetCount() SCONST OVERRIDE
Get the number of items in the list box.
Dropdown Window Class.
Definition SDropDown.h:43
SWindow * GetRoot() const
Gets the root window.
Definition SHostWnd.h:685
List Box Control.
Definition SListbox.h:38
static LPCWSTR GetClassName()
Definition Sobject.hpp:41
A class representing an ASCII string.
Definition sstringw.h:96
BOOL IsEmpty() SCONST
Checks if the string is empty.
BOOL RemoveChild(SWindow *pChild)
Removes a child window from the window tree.
Definition Swnd.cpp:602
void SDispatchMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0) OVERRIDE
Dispatches a message to the window.
Definition Swnd.cpp:388
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
COLORREF m_crColorize
Definition SWnd.h:2628
void InsertChild(SWindow *pNewChild, SWindow *pInsertAfter=NULL)
Inserts a child window into the window tree.
Definition Swnd.cpp:538
static SStringW GetXmlText(const SXmlNode &xmlNode)
Gets the XML text from a node.
Definition Swnd.cpp:2955
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
int as_int(int def=0) const
Converts the attribute value to an integer.
Definition SXml.cpp:100
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
Definition SXml.cpp:95
const wchar_t * value() const
Gets the attribute value.
Definition SXml.cpp:90
Class representing an XML node.
Definition SXml.h:352
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
Definition SXml.cpp:393
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