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/cfwl_combolist.h" | 7 #include "xfa/fwl/core/cfwl_combolist.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
| 13 #include "xfa/fwl/core/cfwl_combobox.h" |
13 #include "xfa/fwl/core/cfwl_comboedit.h" | 14 #include "xfa/fwl/core/cfwl_comboedit.h" |
| 15 #include "xfa/fwl/core/cfwl_listbox.h" |
14 #include "xfa/fwl/core/cfwl_msgkey.h" | 16 #include "xfa/fwl/core/cfwl_msgkey.h" |
15 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 17 #include "xfa/fwl/core/cfwl_msgkillfocus.h" |
16 #include "xfa/fwl/core/cfwl_msgmouse.h" | 18 #include "xfa/fwl/core/cfwl_msgmouse.h" |
17 #include "xfa/fwl/core/ifwl_combobox.h" | |
18 #include "xfa/fwl/core/ifwl_listbox.h" | |
19 | 19 |
20 CFWL_ComboList::CFWL_ComboList( | 20 CFWL_ComboList::CFWL_ComboList( |
21 const CFWL_App* app, | 21 const CFWL_App* app, |
22 std::unique_ptr<CFWL_WidgetProperties> properties, | 22 std::unique_ptr<CFWL_WidgetProperties> properties, |
23 IFWL_Widget* pOuter) | 23 CFWL_Widget* pOuter) |
24 : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { | 24 : CFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { |
25 ASSERT(pOuter); | 25 ASSERT(pOuter); |
26 } | 26 } |
27 | 27 |
28 int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 28 int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
29 if (wsMatch.IsEmpty()) | 29 if (wsMatch.IsEmpty()) |
30 return -1; | 30 return -1; |
31 | 31 |
32 int32_t iCount = CountItems(this); | 32 int32_t iCount = CountItems(this); |
33 for (int32_t i = 0; i < iCount; i++) { | 33 for (int32_t i = 0; i < iCount; i++) { |
34 CFWL_ListItem* hItem = GetItem(this, i); | 34 CFWL_ListItem* hItem = GetItem(this, i); |
(...skipping 26 matching lines...) Expand all Loading... |
61 rtInvalidate.Union(rect); | 61 rtInvalidate.Union(rect); |
62 CFWL_ListItem* hSel = GetItem(this, iSel); | 62 CFWL_ListItem* hSel = 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 } | 67 } |
68 | 68 |
69 void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | 69 void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { |
70 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; | 70 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; |
71 IFWL_Widget* pOwner = GetOwner(); | 71 CFWL_Widget* pOwner = GetOwner(); |
72 if (!pOwner) | 72 if (!pOwner) |
73 return; | 73 return; |
74 pOwner->TransformTo(m_pOuter, fx, fy); | 74 pOwner->TransformTo(m_pOuter, fx, fy); |
75 } | 75 } |
76 | 76 |
77 void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { | 77 void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { |
78 if (!pMessage) | 78 if (!pMessage) |
79 return; | 79 return; |
80 | 80 |
81 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | 81 CFWL_MessageType dwHashCode = pMessage->GetClassID(); |
(...skipping 30 matching lines...) Expand all Loading... |
112 OnDropListLButtonUp(pMsg); | 112 OnDropListLButtonUp(pMsg); |
113 break; | 113 break; |
114 } | 114 } |
115 default: | 115 default: |
116 break; | 116 break; |
117 } | 117 } |
118 } else if (dwHashCode == CFWL_MessageType::Key) { | 118 } else if (dwHashCode == CFWL_MessageType::Key) { |
119 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); | 119 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); |
120 } | 120 } |
121 if (backDefault) | 121 if (backDefault) |
122 IFWL_ListBox::OnProcessMessage(pMessage); | 122 CFWL_ListBox::OnProcessMessage(pMessage); |
123 } | 123 } |
124 | 124 |
125 void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { | 125 void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { |
126 if (bSet) | 126 if (bSet) |
127 return; | 127 return; |
128 | 128 |
129 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | 129 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); |
130 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 130 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
131 if (pKill->m_pSetFocus == m_pOuter || | 131 if (pKill->m_pSetFocus == m_pOuter || |
132 pKill->m_pSetFocus == pOuter->GetComboEdit()) { | 132 pKill->m_pSetFocus == pOuter->GetComboEdit()) { |
133 pOuter->ShowDropList(false); | 133 pOuter->ShowDropList(false); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | 137 void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { |
138 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { | 138 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { |
139 if (m_bNotifyOwner) | 139 if (m_bNotifyOwner) |
140 m_bNotifyOwner = false; | 140 m_bNotifyOwner = false; |
141 | 141 |
142 CFWL_ScrollBar* vertSB = GetVertScrollBar(); | 142 CFWL_ScrollBar* vertSB = GetVertScrollBar(); |
143 if (IsShowScrollBar(true) && vertSB) { | 143 if (IsShowScrollBar(true) && vertSB) { |
144 CFX_RectF rect; | 144 CFX_RectF rect; |
145 vertSB->GetWidgetRect(rect); | 145 vertSB->GetWidgetRect(rect); |
146 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) | 146 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 150 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
151 if (!hItem) | 151 if (!hItem) |
152 return; | 152 return; |
153 | 153 |
154 ChangeSelected(GetItemIndex(this, hItem)); | 154 ChangeSelected(GetItemIndex(this, hItem)); |
155 } else if (m_bNotifyOwner) { | 155 } else if (m_bNotifyOwner) { |
156 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 156 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
157 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 157 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
158 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 158 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 162 void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { |
163 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) | 163 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) |
164 return; | 164 return; |
165 | 165 |
166 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 166 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
167 pOuter->ShowDropList(false); | 167 pOuter->ShowDropList(false); |
168 } | 168 } |
169 | 169 |
170 void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | 170 void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { |
171 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 171 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
172 if (m_bNotifyOwner) { | 172 if (m_bNotifyOwner) { |
173 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 173 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
174 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 174 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
175 return; | 175 return; |
176 } | 176 } |
177 | 177 |
178 CFWL_ScrollBar* vertSB = GetVertScrollBar(); | 178 CFWL_ScrollBar* vertSB = GetVertScrollBar(); |
179 if (IsShowScrollBar(true) && vertSB) { | 179 if (IsShowScrollBar(true) && vertSB) { |
180 CFX_RectF rect; | 180 CFX_RectF rect; |
181 vertSB->GetWidgetRect(rect); | 181 vertSB->GetWidgetRect(rect); |
182 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) | 182 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
183 return; | 183 return; |
184 } | 184 } |
185 pOuter->ShowDropList(false); | 185 pOuter->ShowDropList(false); |
186 | 186 |
187 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 187 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
188 if (hItem) | 188 if (hItem) |
189 pOuter->ProcessSelChanged(true); | 189 pOuter->ProcessSelChanged(true); |
190 } | 190 } |
191 | 191 |
192 bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { | 192 bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { |
193 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 193 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
194 bool bPropagate = false; | 194 bool bPropagate = false; |
195 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 195 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
196 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 196 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
197 switch (dwKeyCode) { | 197 switch (dwKeyCode) { |
198 case FWL_VKEY_Return: | 198 case FWL_VKEY_Return: |
199 case FWL_VKEY_Escape: { | 199 case FWL_VKEY_Escape: { |
200 pOuter->ShowDropList(false); | 200 pOuter->ShowDropList(false); |
201 return true; | 201 return true; |
202 } | 202 } |
203 case FWL_VKEY_Up: | 203 case FWL_VKEY_Up: |
(...skipping 18 matching lines...) Expand all Loading... |
222 return false; | 222 return false; |
223 } | 223 } |
224 | 224 |
225 void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 225 void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
226 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 226 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
227 switch (dwKeyCode) { | 227 switch (dwKeyCode) { |
228 case FWL_VKEY_Up: | 228 case FWL_VKEY_Up: |
229 case FWL_VKEY_Down: | 229 case FWL_VKEY_Down: |
230 case FWL_VKEY_Home: | 230 case FWL_VKEY_Home: |
231 case FWL_VKEY_End: { | 231 case FWL_VKEY_End: { |
232 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 232 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
233 CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); | 233 CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); |
234 hItem = GetListItem(hItem, dwKeyCode); | 234 hItem = GetListItem(hItem, dwKeyCode); |
235 if (!hItem) | 235 if (!hItem) |
236 break; | 236 break; |
237 | 237 |
238 SetSelection(hItem, hItem, true); | 238 SetSelection(hItem, hItem, true); |
239 ScrollToVisible(hItem); | 239 ScrollToVisible(hItem); |
240 CFX_RectF rtInvalidate; | 240 CFX_RectF rtInvalidate; |
241 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 241 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
242 m_pProperties->m_rtWidget.height); | 242 m_pProperties->m_rtWidget.height); |
243 Repaint(&rtInvalidate); | 243 Repaint(&rtInvalidate); |
244 break; | 244 break; |
245 } | 245 } |
246 default: | 246 default: |
247 break; | 247 break; |
248 } | 248 } |
249 } | 249 } |
OLD | NEW |