| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/fwl/core/ifwl_comboboxproxy.h" | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "xfa/fwl/core/cfwl_app.h" | |
| 13 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | |
| 14 #include "xfa/fwl/core/cfwl_msgmouse.h" | |
| 15 #include "xfa/fwl/core/cfwl_notedriver.h" | |
| 16 #include "xfa/fwl/core/ifwl_combobox.h" | |
| 17 | |
| 18 IFWL_ComboBoxProxy::IFWL_ComboBoxProxy( | |
| 19 IFWL_ComboBox* pComboBox, | |
| 20 const CFWL_App* app, | |
| 21 std::unique_ptr<CFWL_WidgetProperties> properties, | |
| 22 IFWL_Widget* pOuter) | |
| 23 : IFWL_FormProxy(app, std::move(properties), pOuter), | |
| 24 m_bLButtonDown(false), | |
| 25 m_bLButtonUpSelf(false), | |
| 26 m_pComboBox(pComboBox) {} | |
| 27 | |
| 28 IFWL_ComboBoxProxy::~IFWL_ComboBoxProxy() {} | |
| 29 | |
| 30 void IFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { | |
| 31 if (!pMessage) | |
| 32 return; | |
| 33 | |
| 34 switch (pMessage->GetClassID()) { | |
| 35 case CFWL_MessageType::Mouse: { | |
| 36 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 37 switch (pMsg->m_dwCmd) { | |
| 38 case FWL_MouseCommand::LeftButtonDown: | |
| 39 OnLButtonDown(pMsg); | |
| 40 break; | |
| 41 case FWL_MouseCommand::LeftButtonUp: | |
| 42 OnLButtonUp(pMsg); | |
| 43 break; | |
| 44 default: | |
| 45 break; | |
| 46 } | |
| 47 break; | |
| 48 } | |
| 49 case CFWL_MessageType::KillFocus: | |
| 50 OnFocusChanged(pMessage, false); | |
| 51 break; | |
| 52 case CFWL_MessageType::SetFocus: | |
| 53 OnFocusChanged(pMessage, true); | |
| 54 break; | |
| 55 default: | |
| 56 break; | |
| 57 } | |
| 58 IFWL_Widget::OnProcessMessage(pMessage); | |
| 59 } | |
| 60 | |
| 61 void IFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 62 const CFX_Matrix* pMatrix) { | |
| 63 m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); | |
| 64 } | |
| 65 | |
| 66 void IFWL_ComboBoxProxy::OnLButtonDown(CFWL_Message* pMessage) { | |
| 67 const CFWL_App* pApp = GetOwnerApp(); | |
| 68 if (!pApp) | |
| 69 return; | |
| 70 | |
| 71 CFWL_NoteDriver* pDriver = | |
| 72 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 73 CFX_RectF rtWidget; | |
| 74 GetWidgetRect(rtWidget); | |
| 75 rtWidget.left = rtWidget.top = 0; | |
| 76 | |
| 77 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 78 if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 79 m_bLButtonDown = true; | |
| 80 pDriver->SetGrab(this, true); | |
| 81 } else { | |
| 82 m_bLButtonDown = false; | |
| 83 pDriver->SetGrab(this, false); | |
| 84 m_pComboBox->ShowDropList(false); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void IFWL_ComboBoxProxy::OnLButtonUp(CFWL_Message* pMessage) { | |
| 89 m_bLButtonDown = false; | |
| 90 const CFWL_App* pApp = GetOwnerApp(); | |
| 91 if (!pApp) | |
| 92 return; | |
| 93 | |
| 94 CFWL_NoteDriver* pDriver = | |
| 95 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 96 pDriver->SetGrab(this, false); | |
| 97 if (!m_bLButtonUpSelf) { | |
| 98 m_bLButtonUpSelf = true; | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 103 CFX_RectF rect; | |
| 104 GetWidgetRect(rect); | |
| 105 rect.left = rect.top = 0; | |
| 106 if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && | |
| 107 m_pComboBox->IsDropListVisible()) { | |
| 108 m_pComboBox->ShowDropList(false); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void IFWL_ComboBoxProxy::OnFocusChanged(CFWL_Message* pMessage, bool bSet) { | |
| 113 if (bSet) | |
| 114 return; | |
| 115 | |
| 116 CFWL_MsgKillFocus* pMsg = static_cast<CFWL_MsgKillFocus*>(pMessage); | |
| 117 if (!pMsg->m_pSetFocus) | |
| 118 m_pComboBox->ShowDropList(false); | |
| 119 } | |
| OLD | NEW |