dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #include "xfa/fwl/cfwl_datetimeedit.h" |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 8 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <utility> |
| 11 | |
dsinclair | 6fe8795 | 2016-11-01 18:48:19 -0700 | [diff] [blame] | 12 | #include "third_party/base/ptr_util.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 13 | #include "xfa/fwl/cfwl_datetimepicker.h" |
| 14 | #include "xfa/fwl/cfwl_messagemouse.h" |
| 15 | #include "xfa/fwl/cfwl_widgetmgr.h" |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 16 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 17 | CFWL_DateTimeEdit::CFWL_DateTimeEdit( |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 18 | const CFWL_App* app, |
dsinclair | a5811f0 | 2016-11-03 12:27:25 -0700 | [diff] [blame] | 19 | std::unique_ptr<CFWL_WidgetProperties> properties, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 20 | CFWL_Widget* pOuter) |
| 21 | : CFWL_Edit(app, std::move(properties), pOuter) {} |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 22 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 23 | void CFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 24 | if (m_pWidgetMgr->IsFormDisabled()) { |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 25 | DisForm_OnProcessMessage(pMessage); |
| 26 | return; |
| 27 | } |
| 28 | |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 29 | CFWL_Message::Type type = pMessage->GetType(); |
| 30 | if (type == CFWL_Message::Type::SetFocus || |
| 31 | type == CFWL_Message::Type::KillFocus) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 32 | CFWL_Widget* pOuter = GetOuter(); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 33 | pOuter->GetDelegate()->OnProcessMessage(pMessage); |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 37 | void CFWL_DateTimeEdit::DisForm_OnProcessMessage(CFWL_Message* pMessage) { |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 38 | if (!m_pWidgetMgr->IsFormDisabled() || |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 39 | pMessage->GetType() != CFWL_Message::Type::Mouse) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 40 | CFWL_Edit::OnProcessMessage(pMessage); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 41 | return; |
| 42 | } |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 43 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 44 | CFWL_MessageMouse* pMouse = static_cast<CFWL_MessageMouse*>(pMessage); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 45 | if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || |
| 46 | pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { |
| 47 | if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
| 48 | m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 49 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 50 | CFWL_DateTimePicker* pDateTime = |
| 51 | static_cast<CFWL_DateTimePicker*>(m_pOuter); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 52 | if (pDateTime->IsMonthCalendarVisible()) { |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 53 | CFX_RectF rtInvalidate = pDateTime->GetWidgetRect(); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 54 | pDateTime->ShowMonthCalendar(false); |
| 55 | rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 56 | pDateTime->RepaintRect(rtInvalidate); |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 59 | CFWL_Edit::OnProcessMessage(pMessage); |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 60 | } |