| 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/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/cfwl_combobox.h" |
| 14 #include "xfa/fwl/core/cfwl_comboedit.h" | 14 #include "xfa/fwl/cfwl_comboedit.h" |
| 15 #include "xfa/fwl/core/cfwl_listbox.h" | 15 #include "xfa/fwl/cfwl_listbox.h" |
| 16 #include "xfa/fwl/core/cfwl_msgkey.h" | 16 #include "xfa/fwl/cfwl_messagekey.h" |
| 17 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 17 #include "xfa/fwl/cfwl_messagekillfocus.h" |
| 18 #include "xfa/fwl/core/cfwl_msgmouse.h" | 18 #include "xfa/fwl/cfwl_messagemouse.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 CFWL_Widget* pOuter) | 23 CFWL_Widget* pOuter) |
| 24 : CFWL_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) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { | 76 void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { |
| 77 if (!pMessage) | 77 if (!pMessage) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 CFWL_Message::Type type = pMessage->GetType(); | 80 CFWL_Message::Type type = pMessage->GetType(); |
| 81 bool backDefault = true; | 81 bool backDefault = true; |
| 82 if (type == CFWL_Message::Type::SetFocus || | 82 if (type == CFWL_Message::Type::SetFocus || |
| 83 type == CFWL_Message::Type::KillFocus) { | 83 type == CFWL_Message::Type::KillFocus) { |
| 84 OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus); | 84 OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus); |
| 85 } else if (type == CFWL_Message::Type::Mouse) { | 85 } else if (type == CFWL_Message::Type::Mouse) { |
| 86 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 86 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
| 87 CFWL_ScrollBar* vertSB = GetVertScrollBar(); | 87 CFWL_ScrollBar* vertSB = GetVertScrollBar(); |
| 88 if (IsShowScrollBar(true) && vertSB) { | 88 if (IsShowScrollBar(true) && vertSB) { |
| 89 CFX_RectF rect = vertSB->GetWidgetRect(); | 89 CFX_RectF rect = vertSB->GetWidgetRect(); |
| 90 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 90 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 91 pMsg->m_fx -= rect.left; | 91 pMsg->m_fx -= rect.left; |
| 92 pMsg->m_fy -= rect.top; | 92 pMsg->m_fy -= rect.top; |
| 93 vertSB->GetDelegate()->OnProcessMessage(pMsg); | 93 vertSB->GetDelegate()->OnProcessMessage(pMsg); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 } | 96 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 } | 107 } |
| 108 case FWL_MouseCommand::LeftButtonUp: { | 108 case FWL_MouseCommand::LeftButtonUp: { |
| 109 backDefault = false; | 109 backDefault = false; |
| 110 OnDropListLButtonUp(pMsg); | 110 OnDropListLButtonUp(pMsg); |
| 111 break; | 111 break; |
| 112 } | 112 } |
| 113 default: | 113 default: |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 } else if (type == CFWL_Message::Type::Key) { | 116 } else if (type == CFWL_Message::Type::Key) { |
| 117 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); | 117 backDefault = !OnDropListKey(static_cast<CFWL_MessageKey*>(pMessage)); |
| 118 } | 118 } |
| 119 if (backDefault) | 119 if (backDefault) |
| 120 CFWL_ListBox::OnProcessMessage(pMessage); | 120 CFWL_ListBox::OnProcessMessage(pMessage); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { | 123 void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 124 if (bSet) | 124 if (bSet) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | 127 CFWL_MessageKillFocus* pKill = static_cast<CFWL_MessageKillFocus*>(pMsg); |
| 128 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 128 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 129 if (pKill->m_pSetFocus == m_pOuter || | 129 if (pKill->m_pSetFocus == m_pOuter || |
| 130 pKill->m_pSetFocus == pOuter->GetComboEdit()) { | 130 pKill->m_pSetFocus == pOuter->GetComboEdit()) { |
| 131 pOuter->ShowDropList(false); | 131 pOuter->ShowDropList(false); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | 135 void CFWL_ComboList::OnDropListMouseMove(CFWL_MessageMouse* pMsg) { |
| 136 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { | 136 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 137 if (m_bNotifyOwner) | 137 if (m_bNotifyOwner) |
| 138 m_bNotifyOwner = false; | 138 m_bNotifyOwner = false; |
| 139 | 139 |
| 140 CFWL_ScrollBar* vertSB = GetVertScrollBar(); | 140 CFWL_ScrollBar* vertSB = GetVertScrollBar(); |
| 141 if (IsShowScrollBar(true) && vertSB) { | 141 if (IsShowScrollBar(true) && vertSB) { |
| 142 CFX_RectF rect = vertSB->GetWidgetRect(); | 142 CFX_RectF rect = vertSB->GetWidgetRect(); |
| 143 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) | 143 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 | 146 |
| 147 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 147 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 148 if (!hItem) | 148 if (!hItem) |
| 149 return; | 149 return; |
| 150 | 150 |
| 151 ChangeSelected(GetItemIndex(this, hItem)); | 151 ChangeSelected(GetItemIndex(this, hItem)); |
| 152 } else if (m_bNotifyOwner) { | 152 } else if (m_bNotifyOwner) { |
| 153 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 153 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
| 154 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 154 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 155 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 155 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 159 void CFWL_ComboList::OnDropListLButtonDown(CFWL_MessageMouse* pMsg) { |
| 160 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) | 160 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 163 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 164 pOuter->ShowDropList(false); | 164 pOuter->ShowDropList(false); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | 167 void CFWL_ComboList::OnDropListLButtonUp(CFWL_MessageMouse* pMsg) { |
| 168 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 168 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 169 if (m_bNotifyOwner) { | 169 if (m_bNotifyOwner) { |
| 170 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 170 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
| 171 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 171 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 CFWL_ScrollBar* vertSB = GetVertScrollBar(); | 175 CFWL_ScrollBar* vertSB = GetVertScrollBar(); |
| 176 if (IsShowScrollBar(true) && vertSB) { | 176 if (IsShowScrollBar(true) && vertSB) { |
| 177 CFX_RectF rect = vertSB->GetWidgetRect(); | 177 CFX_RectF rect = vertSB->GetWidgetRect(); |
| 178 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) | 178 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 pOuter->ShowDropList(false); | 181 pOuter->ShowDropList(false); |
| 182 | 182 |
| 183 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 183 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 184 if (hItem) | 184 if (hItem) |
| 185 pOuter->ProcessSelChanged(true); | 185 pOuter->ProcessSelChanged(true); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { | 188 bool CFWL_ComboList::OnDropListKey(CFWL_MessageKey* pKey) { |
| 189 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 189 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 190 bool bPropagate = false; | 190 bool bPropagate = false; |
| 191 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 191 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
| 192 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 192 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 193 switch (dwKeyCode) { | 193 switch (dwKeyCode) { |
| 194 case FWL_VKEY_Return: | 194 case FWL_VKEY_Return: |
| 195 case FWL_VKEY_Escape: { | 195 case FWL_VKEY_Escape: { |
| 196 pOuter->ShowDropList(false); | 196 pOuter->ShowDropList(false); |
| 197 return true; | 197 return true; |
| 198 } | 198 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 211 bPropagate = true; | 211 bPropagate = true; |
| 212 } | 212 } |
| 213 if (bPropagate) { | 213 if (bPropagate) { |
| 214 pKey->m_pDstTarget = m_pOuter; | 214 pKey->m_pDstTarget = m_pOuter; |
| 215 pOuter->GetDelegate()->OnProcessMessage(pKey); | 215 pOuter->GetDelegate()->OnProcessMessage(pKey); |
| 216 return true; | 216 return true; |
| 217 } | 217 } |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 | 220 |
| 221 void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 221 void CFWL_ComboList::OnDropListKeyDown(CFWL_MessageKey* pKey) { |
| 222 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 222 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 223 switch (dwKeyCode) { | 223 switch (dwKeyCode) { |
| 224 case FWL_VKEY_Up: | 224 case FWL_VKEY_Up: |
| 225 case FWL_VKEY_Down: | 225 case FWL_VKEY_Down: |
| 226 case FWL_VKEY_Home: | 226 case FWL_VKEY_Home: |
| 227 case FWL_VKEY_End: { | 227 case FWL_VKEY_End: { |
| 228 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); | 228 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter); |
| 229 CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); | 229 CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); |
| 230 hItem = GetListItem(hItem, dwKeyCode); | 230 hItem = GetListItem(hItem, dwKeyCode); |
| 231 if (!hItem) | 231 if (!hItem) |
| 232 break; | 232 break; |
| 233 | 233 |
| 234 SetSelection(hItem, hItem, true); | 234 SetSelection(hItem, hItem, true); |
| 235 ScrollToVisible(hItem); | 235 ScrollToVisible(hItem); |
| 236 CFX_RectF rtInvalidate; | 236 CFX_RectF rtInvalidate; |
| 237 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 237 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 238 m_pProperties->m_rtWidget.height); | 238 m_pProperties->m_rtWidget.height); |
| 239 Repaint(&rtInvalidate); | 239 Repaint(&rtInvalidate); |
| 240 break; | 240 break; |
| 241 } | 241 } |
| 242 default: | 242 default: |
| 243 break; | 243 break; |
| 244 } | 244 } |
| 245 } | 245 } |
| OLD | NEW |