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(const IFWL_App* app, | 13 IFWL_ComboList::IFWL_ComboList(const IFWL_App* app, |
14 const CFWL_WidgetImpProperties& properties, | 14 const CFWL_WidgetImpProperties& properties, |
15 IFWL_Widget* pOuter) | 15 IFWL_Widget* pOuter) |
16 : IFWL_ListBox(app, properties, pOuter), m_bNotifyOwner(TRUE) { | 16 : IFWL_ListBox(app, properties, pOuter), m_bNotifyOwner(true) { |
17 ASSERT(pOuter); | 17 ASSERT(pOuter); |
18 } | 18 } |
19 | 19 |
20 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 20 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
21 if (wsMatch.IsEmpty()) { | 21 if (wsMatch.IsEmpty()) { |
22 return -1; | 22 return -1; |
23 } | 23 } |
24 if (!m_pProperties->m_pDataProvider) | 24 if (!m_pProperties->m_pDataProvider) |
25 return -1; | 25 return -1; |
26 IFWL_ListBoxDP* pData = | 26 IFWL_ListBoxDP* pData = |
(...skipping 18 matching lines...) Expand all Loading... |
45 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 45 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
46 IFWL_ListItem* hItem = pData->GetItem(this, iSel); | 46 IFWL_ListItem* hItem = pData->GetItem(this, iSel); |
47 CFX_RectF rtInvalidate; | 47 CFX_RectF rtInvalidate; |
48 rtInvalidate.Reset(); | 48 rtInvalidate.Reset(); |
49 IFWL_ListItem* hOld = GetSelItem(0); | 49 IFWL_ListItem* hOld = GetSelItem(0); |
50 int32_t iOld = pData->GetItemIndex(this, hOld); | 50 int32_t iOld = pData->GetItemIndex(this, hOld); |
51 if (iOld == iSel) { | 51 if (iOld == iSel) { |
52 return; | 52 return; |
53 } else if (iOld > -1) { | 53 } else if (iOld > -1) { |
54 GetItemRect(iOld, rtInvalidate); | 54 GetItemRect(iOld, rtInvalidate); |
55 SetSelItem(hOld, FALSE); | 55 SetSelItem(hOld, false); |
56 } | 56 } |
57 if (hItem) { | 57 if (hItem) { |
58 CFX_RectF rect; | 58 CFX_RectF rect; |
59 GetItemRect(iSel, rect); | 59 GetItemRect(iSel, rect); |
60 rtInvalidate.Union(rect); | 60 rtInvalidate.Union(rect); |
61 IFWL_ListItem* hSel = pData->GetItem(this, iSel); | 61 IFWL_ListItem* hSel = pData->GetItem(this, iSel); |
62 SetSelItem(hSel, TRUE); | 62 SetSelItem(hSel, true); |
63 } | 63 } |
64 if (!rtInvalidate.IsEmpty()) { | 64 if (!rtInvalidate.IsEmpty()) { |
65 Repaint(&rtInvalidate); | 65 Repaint(&rtInvalidate); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 int32_t IFWL_ComboList::CountItems() { | 69 int32_t IFWL_ComboList::CountItems() { |
70 IFWL_ListBoxDP* pData = | 70 IFWL_ListBoxDP* pData = |
71 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 71 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
72 return pData ? pData->CountItems(this) : 0; | 72 return pData ? pData->CountItems(this) : 0; |
73 } | 73 } |
74 | 74 |
75 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { | 75 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { |
76 IFWL_ListBoxDP* pData = | 76 IFWL_ListBoxDP* pData = |
77 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 77 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
78 IFWL_ListItem* hItem = pData->GetItem(this, nIndex); | 78 IFWL_ListItem* hItem = pData->GetItem(this, nIndex); |
79 pData->GetItemRect(this, hItem, rtItem); | 79 pData->GetItemRect(this, hItem, rtItem); |
80 } | 80 } |
81 | 81 |
82 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | 82 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { |
83 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; |
84 IFWL_Widget* pOwner = GetOwner(); | 84 IFWL_Widget* pOwner = GetOwner(); |
85 if (!pOwner) | 85 if (!pOwner) |
86 return; | 86 return; |
87 pOwner->TransformTo(m_pOuter, fx, fy); | 87 pOwner->TransformTo(m_pOuter, fx, fy); |
88 } | 88 } |
89 | 89 |
90 void IFWL_ComboList::SetFocus(FX_BOOL bSet) { | 90 void IFWL_ComboList::SetFocus(bool bSet) { |
91 IFWL_Widget::SetFocus(bSet); | 91 IFWL_Widget::SetFocus(bSet); |
92 } | 92 } |
93 | 93 |
94 void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { | 94 void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { |
95 if (!pMessage) | 95 if (!pMessage) |
96 return; | 96 return; |
97 | 97 |
98 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | 98 CFWL_MessageType dwHashCode = pMessage->GetClassID(); |
99 FX_BOOL backDefault = TRUE; | 99 bool backDefault = true; |
100 if (dwHashCode == CFWL_MessageType::SetFocus || | 100 if (dwHashCode == CFWL_MessageType::SetFocus || |
101 dwHashCode == CFWL_MessageType::KillFocus) { | 101 dwHashCode == CFWL_MessageType::KillFocus) { |
102 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); | 102 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); |
103 } else if (dwHashCode == CFWL_MessageType::Mouse) { | 103 } else if (dwHashCode == CFWL_MessageType::Mouse) { |
104 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 104 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
105 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { | 105 if (IsShowScrollBar(true) && m_pVertScrollBar) { |
106 CFX_RectF rect; | 106 CFX_RectF rect; |
107 m_pVertScrollBar->GetWidgetRect(rect); | 107 m_pVertScrollBar->GetWidgetRect(rect); |
108 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 108 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
109 pMsg->m_fx -= rect.left; | 109 pMsg->m_fx -= rect.left; |
110 pMsg->m_fy -= rect.top; | 110 pMsg->m_fy -= rect.top; |
111 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); | 111 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); |
112 return; | 112 return; |
113 } | 113 } |
114 } | 114 } |
115 switch (pMsg->m_dwCmd) { | 115 switch (pMsg->m_dwCmd) { |
116 case FWL_MouseCommand::Move: { | 116 case FWL_MouseCommand::Move: { |
117 backDefault = FALSE; | 117 backDefault = false; |
118 OnDropListMouseMove(pMsg); | 118 OnDropListMouseMove(pMsg); |
119 break; | 119 break; |
120 } | 120 } |
121 case FWL_MouseCommand::LeftButtonDown: { | 121 case FWL_MouseCommand::LeftButtonDown: { |
122 backDefault = FALSE; | 122 backDefault = false; |
123 OnDropListLButtonDown(pMsg); | 123 OnDropListLButtonDown(pMsg); |
124 break; | 124 break; |
125 } | 125 } |
126 case FWL_MouseCommand::LeftButtonUp: { | 126 case FWL_MouseCommand::LeftButtonUp: { |
127 backDefault = FALSE; | 127 backDefault = false; |
128 OnDropListLButtonUp(pMsg); | 128 OnDropListLButtonUp(pMsg); |
129 break; | 129 break; |
130 } | 130 } |
131 default: | 131 default: |
132 break; | 132 break; |
133 } | 133 } |
134 } else if (dwHashCode == CFWL_MessageType::Key) { | 134 } else if (dwHashCode == CFWL_MessageType::Key) { |
135 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); | 135 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); |
136 } | 136 } |
137 if (backDefault) | 137 if (backDefault) |
138 IFWL_ListBox::OnProcessMessage(pMessage); | 138 IFWL_ListBox::OnProcessMessage(pMessage); |
139 } | 139 } |
140 | 140 |
141 void IFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { | 141 void IFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { |
142 if (bSet) | 142 if (bSet) |
143 return; | 143 return; |
144 | 144 |
145 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | 145 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); |
146 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 146 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
147 if (pKill->m_pSetFocus == m_pOuter || | 147 if (pKill->m_pSetFocus == m_pOuter || |
148 pKill->m_pSetFocus == pOuter->GetComboEdit()) { | 148 pKill->m_pSetFocus == pOuter->GetComboEdit()) { |
149 pOuter->ShowDropList(FALSE); | 149 pOuter->ShowDropList(false); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 int32_t IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | 153 int32_t IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { |
154 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 154 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
155 if (m_bNotifyOwner) { | 155 if (m_bNotifyOwner) { |
156 m_bNotifyOwner = FALSE; | 156 m_bNotifyOwner = false; |
157 } | 157 } |
158 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { | 158 if (IsShowScrollBar(true) && m_pVertScrollBar) { |
159 CFX_RectF rect; | 159 CFX_RectF rect; |
160 m_pVertScrollBar->GetWidgetRect(rect); | 160 m_pVertScrollBar->GetWidgetRect(rect); |
161 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 161 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
162 return 1; | 162 return 1; |
163 } | 163 } |
164 } | 164 } |
165 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 165 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
166 if (hItem) { | 166 if (hItem) { |
167 if (!m_pProperties->m_pDataProvider) | 167 if (!m_pProperties->m_pDataProvider) |
168 return 0; | 168 return 0; |
(...skipping 12 matching lines...) Expand all Loading... |
181 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 181 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
182 } | 182 } |
183 return 1; | 183 return 1; |
184 } | 184 } |
185 | 185 |
186 int32_t IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 186 int32_t IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { |
187 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) | 187 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
188 return 0; | 188 return 0; |
189 | 189 |
190 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 190 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
191 pOuter->ShowDropList(FALSE); | 191 pOuter->ShowDropList(false); |
192 return 1; | 192 return 1; |
193 } | 193 } |
194 | 194 |
195 int32_t IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | 195 int32_t IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { |
196 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 196 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
197 if (m_bNotifyOwner) { | 197 if (m_bNotifyOwner) { |
198 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 198 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
199 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 199 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
200 } else { | 200 } else { |
201 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { | 201 if (IsShowScrollBar(true) && m_pVertScrollBar) { |
202 CFX_RectF rect; | 202 CFX_RectF rect; |
203 m_pVertScrollBar->GetWidgetRect(rect); | 203 m_pVertScrollBar->GetWidgetRect(rect); |
204 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 204 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
205 return 1; | 205 return 1; |
206 } | 206 } |
207 } | 207 } |
208 pOuter->ShowDropList(FALSE); | 208 pOuter->ShowDropList(false); |
209 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 209 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
210 if (hItem) | 210 if (hItem) |
211 pOuter->ProcessSelChanged(TRUE); | 211 pOuter->ProcessSelChanged(true); |
212 } | 212 } |
213 return 1; | 213 return 1; |
214 } | 214 } |
215 | 215 |
216 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { | 216 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { |
217 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 217 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
218 FX_BOOL bPropagate = FALSE; | 218 bool bPropagate = false; |
219 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 219 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
220 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 220 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
221 switch (dwKeyCode) { | 221 switch (dwKeyCode) { |
222 case FWL_VKEY_Return: | 222 case FWL_VKEY_Return: |
223 case FWL_VKEY_Escape: { | 223 case FWL_VKEY_Escape: { |
224 pOuter->ShowDropList(FALSE); | 224 pOuter->ShowDropList(false); |
225 return 1; | 225 return 1; |
226 } | 226 } |
227 case FWL_VKEY_Up: | 227 case FWL_VKEY_Up: |
228 case FWL_VKEY_Down: { | 228 case FWL_VKEY_Down: { |
229 OnDropListKeyDown(pKey); | 229 OnDropListKeyDown(pKey); |
230 pOuter->ProcessSelChanged(FALSE); | 230 pOuter->ProcessSelChanged(false); |
231 return 1; | 231 return 1; |
232 } | 232 } |
233 default: { bPropagate = TRUE; } | 233 default: { bPropagate = true; } |
234 } | 234 } |
235 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { | 235 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { |
236 bPropagate = TRUE; | 236 bPropagate = true; |
237 } | 237 } |
238 if (bPropagate) { | 238 if (bPropagate) { |
239 pKey->m_pDstTarget = m_pOuter; | 239 pKey->m_pDstTarget = m_pOuter; |
240 pOuter->GetDelegate()->OnProcessMessage(pKey); | 240 pOuter->GetDelegate()->OnProcessMessage(pKey); |
241 return 1; | 241 return 1; |
242 } | 242 } |
243 return 0; | 243 return 0; |
244 } | 244 } |
245 | 245 |
246 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 246 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
247 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 247 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
248 switch (dwKeyCode) { | 248 switch (dwKeyCode) { |
249 case FWL_VKEY_Up: | 249 case FWL_VKEY_Up: |
250 case FWL_VKEY_Down: | 250 case FWL_VKEY_Down: |
251 case FWL_VKEY_Home: | 251 case FWL_VKEY_Home: |
252 case FWL_VKEY_End: { | 252 case FWL_VKEY_End: { |
253 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 253 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
254 IFWL_ListBoxDP* pData = | 254 IFWL_ListBoxDP* pData = |
255 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 255 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
256 IFWL_ListItem* hItem = | 256 IFWL_ListItem* hItem = |
257 pData->GetItem(this, pOuter->GetCurrentSelection()); | 257 pData->GetItem(this, pOuter->GetCurrentSelection()); |
258 hItem = GetItem(hItem, dwKeyCode); | 258 hItem = GetItem(hItem, dwKeyCode); |
259 if (!hItem) { | 259 if (!hItem) { |
260 break; | 260 break; |
261 } | 261 } |
262 SetSelection(hItem, hItem, TRUE); | 262 SetSelection(hItem, hItem, true); |
263 ScrollToVisible(hItem); | 263 ScrollToVisible(hItem); |
264 CFX_RectF rtInvalidate; | 264 CFX_RectF rtInvalidate; |
265 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 265 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
266 m_pProperties->m_rtWidget.height); | 266 m_pProperties->m_rtWidget.height); |
267 Repaint(&rtInvalidate); | 267 Repaint(&rtInvalidate); |
268 break; | 268 break; |
269 } | 269 } |
270 default: | 270 default: |
271 break; | 271 break; |
272 } | 272 } |
273 } | 273 } |
OLD | NEW |