| 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 SetDelegate(pdfium::MakeUnique<CFWL_ComboListImpDelegate>(this)); | |
| 19 } | 18 } |
| 20 | 19 |
| 21 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 20 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
| 22 if (wsMatch.IsEmpty()) { | 21 if (wsMatch.IsEmpty()) { |
| 23 return -1; | 22 return -1; |
| 24 } | 23 } |
| 25 if (!m_pProperties->m_pDataProvider) | 24 if (!m_pProperties->m_pDataProvider) |
| 26 return -1; | 25 return -1; |
| 27 IFWL_ListBoxDP* pData = | 26 IFWL_ListBoxDP* pData = |
| 28 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 27 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(FX_BOOL bSet) { | 90 void IFWL_ComboList::SetFocus(FX_BOOL bSet) { |
| 92 IFWL_Widget::SetFocus(bSet); | 91 IFWL_Widget::SetFocus(bSet); |
| 93 } | 92 } |
| 94 | 93 |
| 95 CFWL_ComboListImpDelegate::CFWL_ComboListImpDelegate(IFWL_ComboList* pOwner) | 94 void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { |
| 96 : CFWL_ListBoxImpDelegate(pOwner), m_pOwner(pOwner) {} | |
| 97 | |
| 98 void CFWL_ComboListImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 99 if (!pMessage) | 95 if (!pMessage) |
| 100 return; | 96 return; |
| 101 | 97 |
| 102 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | 98 CFWL_MessageType dwHashCode = pMessage->GetClassID(); |
| 103 FX_BOOL backDefault = TRUE; | 99 FX_BOOL backDefault = TRUE; |
| 104 if (dwHashCode == CFWL_MessageType::SetFocus || | 100 if (dwHashCode == CFWL_MessageType::SetFocus || |
| 105 dwHashCode == CFWL_MessageType::KillFocus) { | 101 dwHashCode == CFWL_MessageType::KillFocus) { |
| 106 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); | 102 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); |
| 107 } else if (dwHashCode == CFWL_MessageType::Mouse) { | 103 } else if (dwHashCode == CFWL_MessageType::Mouse) { |
| 108 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 104 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 109 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | 105 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { |
| 110 CFX_RectF rect; | 106 CFX_RectF rect; |
| 111 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | 107 m_pVertScrollBar->GetWidgetRect(rect); |
| 112 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 108 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 113 pMsg->m_fx -= rect.left; | 109 pMsg->m_fx -= rect.left; |
| 114 pMsg->m_fy -= rect.top; | 110 pMsg->m_fy -= rect.top; |
| 115 m_pOwner->m_pVertScrollBar->GetCurrentDelegate()->OnProcessMessage( | 111 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); |
| 116 pMsg); | |
| 117 return; | 112 return; |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 switch (pMsg->m_dwCmd) { | 115 switch (pMsg->m_dwCmd) { |
| 121 case FWL_MouseCommand::Move: { | 116 case FWL_MouseCommand::Move: { |
| 122 backDefault = FALSE; | 117 backDefault = FALSE; |
| 123 OnDropListMouseMove(pMsg); | 118 OnDropListMouseMove(pMsg); |
| 124 break; | 119 break; |
| 125 } | 120 } |
| 126 case FWL_MouseCommand::LeftButtonDown: { | 121 case FWL_MouseCommand::LeftButtonDown: { |
| 127 backDefault = FALSE; | 122 backDefault = FALSE; |
| 128 OnDropListLButtonDown(pMsg); | 123 OnDropListLButtonDown(pMsg); |
| 129 break; | 124 break; |
| 130 } | 125 } |
| 131 case FWL_MouseCommand::LeftButtonUp: { | 126 case FWL_MouseCommand::LeftButtonUp: { |
| 132 backDefault = FALSE; | 127 backDefault = FALSE; |
| 133 OnDropListLButtonUp(pMsg); | 128 OnDropListLButtonUp(pMsg); |
| 134 break; | 129 break; |
| 135 } | 130 } |
| 136 default: | 131 default: |
| 137 break; | 132 break; |
| 138 } | 133 } |
| 139 } else if (dwHashCode == CFWL_MessageType::Key) { | 134 } else if (dwHashCode == CFWL_MessageType::Key) { |
| 140 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); | 135 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); |
| 141 } | 136 } |
| 142 if (backDefault) | 137 if (backDefault) |
| 143 CFWL_ListBoxImpDelegate::OnProcessMessage(pMessage); | 138 IFWL_ListBox::OnProcessMessage(pMessage); |
| 144 } | 139 } |
| 145 | 140 |
| 146 void CFWL_ComboListImpDelegate::OnDropListFocusChanged(CFWL_Message* pMsg, | 141 void IFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
| 147 FX_BOOL bSet) { | 142 if (bSet) |
| 148 if (!bSet) { | 143 return; |
| 149 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | 144 |
| 150 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 145 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); |
| 151 if (pKill->m_pSetFocus == m_pOwner->m_pOuter || | 146 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 152 pKill->m_pSetFocus == pOuter->m_pEdit.get()) { | 147 if (pKill->m_pSetFocus == m_pOuter || |
| 153 pOuter->ShowDropList(FALSE); | 148 pKill->m_pSetFocus == pOuter->GetComboEdit()) { |
| 154 } | 149 pOuter->ShowDropList(FALSE); |
| 155 } | 150 } |
| 156 } | 151 } |
| 157 | 152 |
| 158 int32_t CFWL_ComboListImpDelegate::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | 153 int32_t IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { |
| 159 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 154 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 160 if (m_pOwner->m_bNotifyOwner) { | 155 if (m_bNotifyOwner) { |
| 161 m_pOwner->m_bNotifyOwner = FALSE; | 156 m_bNotifyOwner = FALSE; |
| 162 } | 157 } |
| 163 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | 158 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { |
| 164 CFX_RectF rect; | 159 CFX_RectF rect; |
| 165 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | 160 m_pVertScrollBar->GetWidgetRect(rect); |
| 166 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 161 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 167 return 1; | 162 return 1; |
| 168 } | 163 } |
| 169 } | 164 } |
| 170 IFWL_ListItem* hItem = m_pOwner->GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 165 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 171 if (hItem) { | 166 if (hItem) { |
| 172 if (!m_pOwner->m_pProperties->m_pDataProvider) | 167 if (!m_pProperties->m_pDataProvider) |
| 173 return 0; | 168 return 0; |
| 174 IFWL_ListBoxDP* pData = static_cast<IFWL_ListBoxDP*>( | 169 IFWL_ListBoxDP* pData = |
| 175 m_pOwner->m_pProperties->m_pDataProvider); | 170 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 176 int32_t iSel = pData->GetItemIndex(m_pOwner, hItem); | 171 int32_t iSel = pData->GetItemIndex(this, hItem); |
| 177 CFWL_EvtCmbHoverChanged event; | 172 CFWL_EvtCmbHoverChanged event; |
| 178 event.m_pSrcTarget = m_pOwner->m_pOuter; | 173 event.m_pSrcTarget = m_pOuter; |
| 179 event.m_iCurHover = iSel; | 174 event.m_iCurHover = iSel; |
| 180 m_pOwner->DispatchEvent(&event); | 175 DispatchEvent(&event); |
| 181 m_pOwner->ChangeSelected(iSel); | 176 ChangeSelected(iSel); |
| 182 } | 177 } |
| 183 } else if (m_pOwner->m_bNotifyOwner) { | 178 } else if (m_bNotifyOwner) { |
| 184 m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 179 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
| 185 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 180 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 186 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 181 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 187 } | 182 } |
| 188 return 1; | 183 return 1; |
| 189 } | 184 } |
| 190 | 185 |
| 191 int32_t CFWL_ComboListImpDelegate::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 186 int32_t IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { |
| 192 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 187 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 193 return 0; | 188 return 0; |
| 194 } | 189 |
| 195 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 190 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 196 pOuter->ShowDropList(FALSE); | 191 pOuter->ShowDropList(FALSE); |
| 197 return 1; | 192 return 1; |
| 198 } | 193 } |
| 199 | 194 |
| 200 int32_t CFWL_ComboListImpDelegate::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | 195 int32_t IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { |
| 201 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 196 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 202 if (m_pOwner->m_bNotifyOwner) { | 197 if (m_bNotifyOwner) { |
| 203 m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 198 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
| 204 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 199 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 205 } else { | 200 } else { |
| 206 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | 201 if (IsShowScrollBar(TRUE) && m_pVertScrollBar) { |
| 207 CFX_RectF rect; | 202 CFX_RectF rect; |
| 208 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | 203 m_pVertScrollBar->GetWidgetRect(rect); |
| 209 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 204 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 210 return 1; | 205 return 1; |
| 211 } | 206 } |
| 212 } | 207 } |
| 213 pOuter->ShowDropList(FALSE); | 208 pOuter->ShowDropList(FALSE); |
| 214 IFWL_ListItem* hItem = m_pOwner->GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 209 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 215 if (hItem) { | 210 if (hItem) |
| 216 pOuter->ProcessSelChanged(TRUE); | 211 pOuter->ProcessSelChanged(TRUE); |
| 217 } | |
| 218 } | 212 } |
| 219 return 1; | 213 return 1; |
| 220 } | 214 } |
| 221 | 215 |
| 222 int32_t CFWL_ComboListImpDelegate::OnDropListKey(CFWL_MsgKey* pKey) { | 216 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { |
| 223 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 217 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 224 FX_BOOL bPropagate = FALSE; | 218 FX_BOOL bPropagate = FALSE; |
| 225 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 219 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
| 226 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 220 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 227 switch (dwKeyCode) { | 221 switch (dwKeyCode) { |
| 228 case FWL_VKEY_Return: | 222 case FWL_VKEY_Return: |
| 229 case FWL_VKEY_Escape: { | 223 case FWL_VKEY_Escape: { |
| 230 pOuter->ShowDropList(FALSE); | 224 pOuter->ShowDropList(FALSE); |
| 231 return 1; | 225 return 1; |
| 232 } | 226 } |
| 233 case FWL_VKEY_Up: | 227 case FWL_VKEY_Up: |
| 234 case FWL_VKEY_Down: { | 228 case FWL_VKEY_Down: { |
| 235 OnDropListKeyDown(pKey); | 229 OnDropListKeyDown(pKey); |
| 236 pOuter->ProcessSelChanged(FALSE); | 230 pOuter->ProcessSelChanged(FALSE); |
| 237 return 1; | 231 return 1; |
| 238 } | 232 } |
| 239 default: { bPropagate = TRUE; } | 233 default: { bPropagate = TRUE; } |
| 240 } | 234 } |
| 241 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { | 235 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { |
| 242 bPropagate = TRUE; | 236 bPropagate = TRUE; |
| 243 } | 237 } |
| 244 if (bPropagate) { | 238 if (bPropagate) { |
| 245 pKey->m_pDstTarget = m_pOwner->m_pOuter; | 239 pKey->m_pDstTarget = m_pOuter; |
| 246 pOuter->GetDelegate()->OnProcessMessage(pKey); | 240 pOuter->GetDelegate()->OnProcessMessage(pKey); |
| 247 return 1; | 241 return 1; |
| 248 } | 242 } |
| 249 return 0; | 243 return 0; |
| 250 } | 244 } |
| 251 | 245 |
| 252 void CFWL_ComboListImpDelegate::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 246 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
| 253 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 247 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 254 switch (dwKeyCode) { | 248 switch (dwKeyCode) { |
| 255 case FWL_VKEY_Up: | 249 case FWL_VKEY_Up: |
| 256 case FWL_VKEY_Down: | 250 case FWL_VKEY_Down: |
| 257 case FWL_VKEY_Home: | 251 case FWL_VKEY_Home: |
| 258 case FWL_VKEY_End: { | 252 case FWL_VKEY_End: { |
| 259 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOwner->m_pOuter); | 253 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 260 IFWL_ListBoxDP* pData = static_cast<IFWL_ListBoxDP*>( | 254 IFWL_ListBoxDP* pData = |
| 261 m_pOwner->m_pProperties->m_pDataProvider); | 255 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 262 IFWL_ListItem* hItem = pData->GetItem(m_pOwner, pOuter->m_iCurSel); | 256 IFWL_ListItem* hItem = |
| 263 hItem = m_pOwner->GetItem(hItem, dwKeyCode); | 257 pData->GetItem(this, pOuter->GetCurrentSelection()); |
| 258 hItem = GetItem(hItem, dwKeyCode); |
| 264 if (!hItem) { | 259 if (!hItem) { |
| 265 break; | 260 break; |
| 266 } | 261 } |
| 267 m_pOwner->SetSelection(hItem, hItem, TRUE); | 262 SetSelection(hItem, hItem, TRUE); |
| 268 m_pOwner->ScrollToVisible(hItem); | 263 ScrollToVisible(hItem); |
| 269 CFX_RectF rtInvalidate; | 264 CFX_RectF rtInvalidate; |
| 270 rtInvalidate.Set(0, 0, m_pOwner->m_pProperties->m_rtWidget.width, | 265 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 271 m_pOwner->m_pProperties->m_rtWidget.height); | 266 m_pProperties->m_rtWidget.height); |
| 272 m_pOwner->Repaint(&rtInvalidate); | 267 Repaint(&rtInvalidate); |
| 273 break; | 268 break; |
| 274 } | 269 } |
| 275 default: | 270 default: |
| 276 break; | 271 break; |
| 277 } | 272 } |
| 278 } | 273 } |
| OLD | NEW |