-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSearchDropdownList.cpp
192 lines (160 loc) · 5.76 KB
/
SSearchDropdownList.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "stdafx.h"
#include "SSearchDropdownList.h"
namespace SOUI
{
const wchar_t * KNode_PopupStyle = L"popupStyle";
const wchar_t * KName_ListView = L"lv_dropdown";
const wchar_t * KName_SearchEdit = L"edit_input";
SSearchDropdownList::SSearchDropdownList(void):m_nDropAlign(DROPALIGN_RIGHT),m_nMaxDropHeight(150),m_pDropDownWnd(NULL)
{
GetEventSet()->addEvent(EVENTID(EventFillSearchDropdownList));
GetEventSet()->addEvent(EVENTID(EventDropdownListSelected));
}
SSearchDropdownList::~SSearchDropdownList(void)
{
}
bool SSearchDropdownList::OnEditNotify(EventArgs *e)
{
EventRENotify *pEvtNotify = sobj_cast<EventRENotify>(e);
if(pEvtNotify->iNotify == EN_CHANGE)
{
if(!m_pDropDownWnd)
{
m_pDropDownWnd = new SDropdownList(this);
m_pDropDownWnd -> Create(m_xmlDropdown.child(KNode_PopupStyle));
SASSERT(m_pDropDownWnd);
}
EventFillSearchDropdownList evt(this);
evt.strKey = sobj_cast<SEdit>(e->sender)->GetWindowText();
evt.pDropdownWnd = m_pDropDownWnd;
FireEvent(evt);
if(evt.bPopup)
{
AdjustDropdownList();
}else
{
CloseUp(IDCANCEL);
}
}
return true;
}
void SSearchDropdownList::SetDropdownList(IDropdownList *p)
{
}
void SSearchDropdownList::AdjustDropdownList()
{
SASSERT(m_pDropDownWnd);
CRect rcWnd=GetWindowRect();
GetContainer()->FrameToHost(rcWnd);
ClientToScreen(GetContainer()->GetHostHwnd(),(LPPOINT)&rcWnd);
ClientToScreen(GetContainer()->GetHostHwnd(),((LPPOINT)&rcWnd)+1);
HMONITOR hMonitor = ::MonitorFromWindow(GetContainer()->GetHostHwnd(), MONITOR_DEFAULTTONULL);
CRect rcMonitor;
if (hMonitor)
{
MONITORINFO mi = {sizeof(MONITORINFO)};
::GetMonitorInfo(hMonitor, &mi);
rcMonitor = mi.rcMonitor;
}
else
{
rcMonitor.right = GetSystemMetrics( SM_CXSCREEN );
rcMonitor.bottom = GetSystemMetrics( SM_CYSCREEN );
}
CSize szDropdown = m_pDropDownWnd->GetDesiredSize();
if(szDropdown.cy > m_nMaxDropHeight) szDropdown.cy = m_nMaxDropHeight;
CPoint pt;
pt.x = m_nDropAlign == DROPALIGN_LEFT?rcWnd.left : (rcWnd.right - szDropdown.cx);
if(rcWnd.bottom+szDropdown.cy<=rcMonitor.bottom)
{
pt.y = rcWnd.bottom;
}else
{
pt.y = rcWnd.top - szDropdown.cy;
}
m_pDropDownWnd->SetWindowPos(HWND_TOPMOST,pt.x,pt.y,szDropdown.cx,szDropdown.cy,SWP_SHOWWINDOW|SWP_NOACTIVATE);
m_pDropDownWnd->SNativeWnd::SetCapture();
}
SWindow * SSearchDropdownList::GetDropDownOwner()
{
return this;
}
void SSearchDropdownList::OnCreateDropDown(SDropDownWnd *pDropDown)
{
}
void SSearchDropdownList::OnDestroyDropDown(SDropDownWnd *pDropDown)
{
if(pDropDown->GetExitCode() == IDOK)
{
//selected item
EventDropdownListSelected evt(this);
evt.pDropdownWnd = pDropDown;
evt.nValue = pDropDown->GetValue();
FireEvent(evt);
}
m_pDropDownWnd = NULL;
}
void SSearchDropdownList::CloseUp(UINT uCode)
{
if(m_pDropDownWnd)
{
m_pDropDownWnd->EndDropDown(uCode);
}
}
BOOL SSearchDropdownList::CreateChildren(pugi::xml_node xmlNode)
{
BOOL bRet = __super::CreateChildren(xmlNode);
if(!bRet) return FALSE;
SEdit *pEdit = FindChildByName2<SEdit>(KName_SearchEdit);
if(!pEdit) {
return FALSE;
}
pEdit->SSendMessage(EM_SETEVENTMASK,0,ENM_CHANGE);
pEdit->GetEventSet()->subscribeEvent(EVT_RE_NOTIFY,Subscriber(&SSearchDropdownList::OnEditNotify,this));
m_xmlDropdown.append_copy(xmlNode.child(KNode_PopupStyle));
return TRUE;
}
BOOL SSearchDropdownList::FireEvent(EventArgs &evt)
{
if(wcscmp(evt.nameFrom,KName_ListView) == 0)
{
if(evt.GetID() == EVT_CMD)
{
CloseUp(IDOK);
return TRUE;
}
}
return __super::FireEvent(evt);
}
//////////////////////////////////////////////////////////////////////////
SDropdownList::SDropdownList(ISDropDownOwner * pOwner):SDropDownWnd(pOwner),m_pListView(NULL)
{
}
BOOL SDropdownList::Create(pugi::xml_node popupStyle)
{
HWND hParent = m_pOwner->GetDropDownOwner()->GetContainer()->GetHostHwnd();
HWND hWnd=SNativeWnd::Create(NULL,WS_POPUP,WS_EX_TOPMOST|WS_EX_TOOLWINDOW,0,0,0,0,hParent,0);
if(!hWnd) return FALSE;
m_pOwner->OnCreateDropDown(this);
if(popupStyle)
{
InitFromXml(popupStyle);
m_pListView =FindChildByName2<SListView>(KName_ListView);
m_pListView->SetOwner(m_pOwner->GetDropDownOwner());
m_pListView->SetFocus();
}
return TRUE;
}
SIZE SDropdownList::GetDesiredSize()
{
CRect rcOwner = m_pOwner->GetDropDownOwner()->GetWindowRect();
CSize szRet = rcOwner.Size();
SASSERT(m_pListView);
szRet.cy = m_pListView->GetItemLocator()->GetTotalHeight()+2;
return szRet;
}
int SDropdownList::GetValue() const
{
return m_pListView->GetSel();
}
}