OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/ifwl_combolist.h" | 7 #include "xfa/fwl/core/ifwl_combolist.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fwl/core/ifwl_combobox.h" | 10 #include "xfa/fwl/core/ifwl_combobox.h" |
11 #include "xfa/fwl/core/ifwl_comboedit.h" | 11 #include "xfa/fwl/core/ifwl_comboedit.h" |
12 | 12 |
13 IFWL_ComboList::IFWL_ComboList( | 13 IFWL_ComboList::IFWL_ComboList( |
14 const IFWL_App* app, | 14 const IFWL_App* app, |
15 std::unique_ptr<CFWL_WidgetProperties> properties, | 15 std::unique_ptr<CFWL_WidgetProperties> properties, |
16 IFWL_Widget* pOuter) | 16 IFWL_Widget* pOuter) |
17 : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { | 17 : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { |
18 ASSERT(pOuter); | 18 ASSERT(pOuter); |
19 } | 19 } |
20 | 20 |
21 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 21 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
22 if (wsMatch.IsEmpty()) { | 22 if (wsMatch.IsEmpty()) |
23 return -1; | 23 return -1; |
24 } | |
25 if (!m_pProperties->m_pDataProvider) | 24 if (!m_pProperties->m_pDataProvider) |
26 return -1; | 25 return -1; |
| 26 |
27 IFWL_ListBoxDP* pData = | 27 IFWL_ListBoxDP* pData = |
28 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 28 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
29 int32_t iCount = pData->CountItems(this); | 29 int32_t iCount = pData->CountItems(this); |
30 for (int32_t i = 0; i < iCount; i++) { | 30 for (int32_t i = 0; i < iCount; i++) { |
31 CFWL_ListItem* hItem = pData->GetItem(this, i); | 31 CFWL_ListItem* hItem = pData->GetItem(this, i); |
32 CFX_WideString wsText; | 32 CFX_WideString wsText; |
33 pData->GetItemText(this, hItem, wsText); | 33 pData->GetItemText(this, hItem, wsText); |
34 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); | 34 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); |
35 if (!pos) { | 35 if (!pos) |
36 return i; | 36 return i; |
37 } | |
38 } | 37 } |
39 return -1; | 38 return -1; |
40 } | 39 } |
41 | 40 |
42 void IFWL_ComboList::ChangeSelected(int32_t iSel) { | 41 void IFWL_ComboList::ChangeSelected(int32_t iSel) { |
43 if (!m_pProperties->m_pDataProvider) | 42 if (!m_pProperties->m_pDataProvider) |
44 return; | 43 return; |
| 44 |
45 IFWL_ListBoxDP* pData = | 45 IFWL_ListBoxDP* pData = |
46 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 46 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
47 CFWL_ListItem* hItem = pData->GetItem(this, iSel); | 47 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
48 CFX_RectF rtInvalidate; | 48 CFX_RectF rtInvalidate; |
49 rtInvalidate.Reset(); | 49 rtInvalidate.Reset(); |
50 CFWL_ListItem* hOld = GetSelItem(0); | 50 CFWL_ListItem* hOld = GetSelItem(0); |
51 int32_t iOld = pData->GetItemIndex(this, hOld); | 51 int32_t iOld = pData->GetItemIndex(this, hOld); |
52 if (iOld == iSel) { | 52 if (iOld == iSel) |
53 return; | 53 return; |
54 } else if (iOld > -1) { | 54 if (iOld > -1) { |
55 GetItemRect(iOld, rtInvalidate); | 55 GetItemRect(iOld, rtInvalidate); |
56 SetSelItem(hOld, false); | 56 SetSelItem(hOld, false); |
57 } | 57 } |
58 if (hItem) { | 58 if (hItem) { |
59 CFX_RectF rect; | 59 CFX_RectF rect; |
60 GetItemRect(iSel, rect); | 60 GetItemRect(iSel, rect); |
61 rtInvalidate.Union(rect); | 61 rtInvalidate.Union(rect); |
62 CFWL_ListItem* hSel = pData->GetItem(this, iSel); | 62 CFWL_ListItem* hSel = pData->GetItem(this, iSel); |
63 SetSelItem(hSel, true); | 63 SetSelItem(hSel, true); |
64 } | 64 } |
65 if (!rtInvalidate.IsEmpty()) { | 65 if (!rtInvalidate.IsEmpty()) |
66 Repaint(&rtInvalidate); | 66 Repaint(&rtInvalidate); |
67 } | |
68 } | 67 } |
69 | 68 |
70 int32_t IFWL_ComboList::CountItems() { | 69 int32_t IFWL_ComboList::CountItems() { |
71 IFWL_ListBoxDP* pData = | 70 IFWL_ListBoxDP* pData = |
72 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 71 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
73 return pData ? pData->CountItems(this) : 0; | 72 return pData ? pData->CountItems(this) : 0; |
74 } | 73 } |
75 | 74 |
76 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { | 75 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { |
77 IFWL_ListBoxDP* pData = | 76 IFWL_ListBoxDP* pData = |
78 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 77 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
79 CFWL_ListItem* hItem = pData->GetItem(this, nIndex); | 78 CFWL_ListItem* hItem = pData->GetItem(this, nIndex); |
80 pData->GetItemRect(this, hItem, rtItem); | 79 pData->GetItemRect(this, hItem, rtItem); |
81 } | 80 } |
82 | 81 |
83 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | 82 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { |
84 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; | 83 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; |
85 IFWL_Widget* pOwner = GetOwner(); | 84 IFWL_Widget* pOwner = GetOwner(); |
86 if (!pOwner) | 85 if (!pOwner) |
87 return; | 86 return; |
88 pOwner->TransformTo(m_pOuter, fx, fy); | 87 pOwner->TransformTo(m_pOuter, fx, fy); |
89 } | 88 } |
90 | 89 |
91 void IFWL_ComboList::SetFocus(bool bSet) { | |
92 IFWL_Widget::SetFocus(bSet); | |
93 } | |
94 | |
95 void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { | 90 void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { |
96 if (!pMessage) | 91 if (!pMessage) |
97 return; | 92 return; |
98 | 93 |
99 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | 94 CFWL_MessageType dwHashCode = pMessage->GetClassID(); |
100 bool backDefault = true; | 95 bool backDefault = true; |
101 if (dwHashCode == CFWL_MessageType::SetFocus || | 96 if (dwHashCode == CFWL_MessageType::SetFocus || |
102 dwHashCode == CFWL_MessageType::KillFocus) { | 97 dwHashCode == CFWL_MessageType::KillFocus) { |
103 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); | 98 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); |
104 } else if (dwHashCode == CFWL_MessageType::Mouse) { | 99 } else if (dwHashCode == CFWL_MessageType::Mouse) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return; | 140 return; |
146 | 141 |
147 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | 142 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); |
148 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 143 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
149 if (pKill->m_pSetFocus == m_pOuter || | 144 if (pKill->m_pSetFocus == m_pOuter || |
150 pKill->m_pSetFocus == pOuter->GetComboEdit()) { | 145 pKill->m_pSetFocus == pOuter->GetComboEdit()) { |
151 pOuter->ShowDropList(false); | 146 pOuter->ShowDropList(false); |
152 } | 147 } |
153 } | 148 } |
154 | 149 |
155 int32_t IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | 150 void IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { |
156 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { | 151 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { |
157 if (m_bNotifyOwner) { | 152 if (m_bNotifyOwner) |
158 m_bNotifyOwner = false; | 153 m_bNotifyOwner = false; |
159 } | 154 |
160 IFWL_ScrollBar* vertSB = GetVertScrollBar(); | 155 IFWL_ScrollBar* vertSB = GetVertScrollBar(); |
161 if (IsShowScrollBar(true) && vertSB) { | 156 if (IsShowScrollBar(true) && vertSB) { |
162 CFX_RectF rect; | 157 CFX_RectF rect; |
163 vertSB->GetWidgetRect(rect); | 158 vertSB->GetWidgetRect(rect); |
164 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 159 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
165 return 1; | 160 return; |
166 } | |
167 } | 161 } |
| 162 |
168 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 163 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
169 if (hItem) { | 164 if (!hItem) |
170 if (!m_pProperties->m_pDataProvider) | 165 return; |
171 return 0; | 166 if (!m_pProperties->m_pDataProvider) |
172 IFWL_ListBoxDP* pData = | 167 return; |
173 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 168 |
174 int32_t iSel = pData->GetItemIndex(this, hItem); | 169 IFWL_ListBoxDP* pData = |
175 CFWL_EvtCmbHoverChanged event; | 170 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
176 event.m_pSrcTarget = m_pOuter; | 171 int32_t iSel = pData->GetItemIndex(this, hItem); |
177 event.m_iCurHover = iSel; | 172 CFWL_EvtCmbHoverChanged event; |
178 DispatchEvent(&event); | 173 event.m_pSrcTarget = m_pOuter; |
179 ChangeSelected(iSel); | 174 event.m_iCurHover = iSel; |
180 } | 175 DispatchEvent(&event); |
| 176 ChangeSelected(iSel); |
181 } else if (m_bNotifyOwner) { | 177 } else if (m_bNotifyOwner) { |
182 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 178 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
183 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 179 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
184 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 180 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
185 } | 181 } |
186 return 1; | |
187 } | 182 } |
188 | 183 |
189 int32_t IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 184 void IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { |
190 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) | 185 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) |
191 return 0; | 186 return; |
192 | 187 |
193 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 188 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
194 pOuter->ShowDropList(false); | 189 pOuter->ShowDropList(false); |
195 return 1; | |
196 } | 190 } |
197 | 191 |
198 int32_t IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | 192 void IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { |
199 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 193 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
200 if (m_bNotifyOwner) { | 194 if (m_bNotifyOwner) { |
201 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 195 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
202 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 196 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
203 } else { | 197 return; |
204 IFWL_ScrollBar* vertSB = GetVertScrollBar(); | |
205 if (IsShowScrollBar(true) && vertSB) { | |
206 CFX_RectF rect; | |
207 vertSB->GetWidgetRect(rect); | |
208 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
209 return 1; | |
210 } | |
211 } | |
212 pOuter->ShowDropList(false); | |
213 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | |
214 if (hItem) | |
215 pOuter->ProcessSelChanged(true); | |
216 } | 198 } |
217 return 1; | 199 |
| 200 IFWL_ScrollBar* vertSB = GetVertScrollBar(); |
| 201 if (IsShowScrollBar(true) && vertSB) { |
| 202 CFX_RectF rect; |
| 203 vertSB->GetWidgetRect(rect); |
| 204 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 205 return; |
| 206 } |
| 207 pOuter->ShowDropList(false); |
| 208 |
| 209 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 210 if (hItem) |
| 211 pOuter->ProcessSelChanged(true); |
218 } | 212 } |
219 | 213 |
220 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { | 214 bool IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { |
221 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 215 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
222 bool bPropagate = false; | 216 bool bPropagate = false; |
223 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 217 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
224 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 218 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
225 switch (dwKeyCode) { | 219 switch (dwKeyCode) { |
226 case FWL_VKEY_Return: | 220 case FWL_VKEY_Return: |
227 case FWL_VKEY_Escape: { | 221 case FWL_VKEY_Escape: { |
228 pOuter->ShowDropList(false); | 222 pOuter->ShowDropList(false); |
229 return 1; | 223 return true; |
230 } | 224 } |
231 case FWL_VKEY_Up: | 225 case FWL_VKEY_Up: |
232 case FWL_VKEY_Down: { | 226 case FWL_VKEY_Down: { |
233 OnDropListKeyDown(pKey); | 227 OnDropListKeyDown(pKey); |
234 pOuter->ProcessSelChanged(false); | 228 pOuter->ProcessSelChanged(false); |
235 return 1; | 229 return true; |
236 } | 230 } |
237 default: { bPropagate = true; } | 231 default: { |
| 232 bPropagate = true; |
| 233 break; |
| 234 } |
238 } | 235 } |
239 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { | 236 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { |
240 bPropagate = true; | 237 bPropagate = true; |
241 } | 238 } |
242 if (bPropagate) { | 239 if (bPropagate) { |
243 pKey->m_pDstTarget = m_pOuter; | 240 pKey->m_pDstTarget = m_pOuter; |
244 pOuter->GetDelegate()->OnProcessMessage(pKey); | 241 pOuter->GetDelegate()->OnProcessMessage(pKey); |
245 return 1; | 242 return true; |
246 } | 243 } |
247 return 0; | 244 return false; |
248 } | 245 } |
249 | 246 |
250 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 247 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
251 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 248 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
252 switch (dwKeyCode) { | 249 switch (dwKeyCode) { |
253 case FWL_VKEY_Up: | 250 case FWL_VKEY_Up: |
254 case FWL_VKEY_Down: | 251 case FWL_VKEY_Down: |
255 case FWL_VKEY_Home: | 252 case FWL_VKEY_Home: |
256 case FWL_VKEY_End: { | 253 case FWL_VKEY_End: { |
257 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 254 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
258 IFWL_ListBoxDP* pData = | 255 IFWL_ListBoxDP* pData = |
259 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 256 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
260 CFWL_ListItem* hItem = | 257 CFWL_ListItem* hItem = |
261 pData->GetItem(this, pOuter->GetCurrentSelection()); | 258 pData->GetItem(this, pOuter->GetCurrentSelection()); |
262 hItem = GetItem(hItem, dwKeyCode); | 259 hItem = GetItem(hItem, dwKeyCode); |
263 if (!hItem) { | 260 if (!hItem) |
264 break; | 261 break; |
265 } | 262 |
266 SetSelection(hItem, hItem, true); | 263 SetSelection(hItem, hItem, true); |
267 ScrollToVisible(hItem); | 264 ScrollToVisible(hItem); |
268 CFX_RectF rtInvalidate; | 265 CFX_RectF rtInvalidate; |
269 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 266 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
270 m_pProperties->m_rtWidget.height); | 267 m_pProperties->m_rtWidget.height); |
271 Repaint(&rtInvalidate); | 268 Repaint(&rtInvalidate); |
272 break; | 269 break; |
273 } | 270 } |
274 default: | 271 default: |
275 break; | 272 break; |
276 } | 273 } |
277 } | 274 } |
OLD | NEW |