OLD | NEW |
(Empty) | |
| 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 |
| 7 #include "xfa/fwl/core/ifwl_datetimecalendar.h" |
| 8 |
| 9 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
| 10 #include "xfa/fwl/core/ifwl_datetimepicker.h" |
| 11 #include "xfa/fwl/core/ifwl_formproxy.h" |
| 12 |
| 13 // static |
| 14 IFWL_DateTimeCalendar* IFWL_DateTimeCalendar::Create( |
| 15 const CFWL_WidgetImpProperties& properties, |
| 16 IFWL_Widget* pOuter) { |
| 17 return new IFWL_DateTimeCalendar(properties, pOuter); |
| 18 } |
| 19 |
| 20 IFWL_DateTimeCalendar::IFWL_DateTimeCalendar( |
| 21 const CFWL_WidgetImpProperties& properties, |
| 22 IFWL_Widget* pOuter) |
| 23 : IFWL_MonthCalendar(properties, pOuter) {} |
| 24 |
| 25 FWL_Error IFWL_DateTimeCalendar::Initialize() { |
| 26 if (IFWL_MonthCalendar::Initialize() != FWL_Error::Succeeded) |
| 27 return FWL_Error::Indefinite; |
| 28 delete m_pDelegate; |
| 29 m_pDelegate = new CFWL_DateTimeCalendarImpDelegate(this); |
| 30 return FWL_Error::Succeeded; |
| 31 } |
| 32 |
| 33 FWL_Error IFWL_DateTimeCalendar::Finalize() { |
| 34 delete m_pDelegate; |
| 35 m_pDelegate = nullptr; |
| 36 return IFWL_MonthCalendar::Finalize(); |
| 37 } |
| 38 |
| 39 CFWL_DateTimeCalendarImpDelegate::CFWL_DateTimeCalendarImpDelegate( |
| 40 IFWL_DateTimeCalendar* pOwner) |
| 41 : CFWL_MonthCalendarImpDelegate(pOwner), m_pOwner(pOwner) { |
| 42 m_bFlag = FALSE; |
| 43 } |
| 44 |
| 45 void CFWL_DateTimeCalendarImpDelegate::OnProcessMessage( |
| 46 CFWL_Message* pMessage) { |
| 47 CFWL_MessageType dwCode = pMessage->GetClassID(); |
| 48 if (dwCode == CFWL_MessageType::SetFocus || |
| 49 dwCode == CFWL_MessageType::KillFocus) { |
| 50 IFWL_Widget* pOuter = m_pOwner->GetOuter(); |
| 51 IFWL_WidgetDelegate* pDelegate = pOuter->SetDelegate(nullptr); |
| 52 pDelegate->OnProcessMessage(pMessage); |
| 53 return; |
| 54 } |
| 55 if (dwCode == CFWL_MessageType::Mouse) { |
| 56 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 57 if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) |
| 58 OnLButtonDownEx(pMsg); |
| 59 else if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) |
| 60 OnLButtonUpEx(pMsg); |
| 61 return; |
| 62 } |
| 63 CFWL_MonthCalendarImpDelegate::OnProcessMessage(pMessage); |
| 64 } |
| 65 |
| 66 void CFWL_DateTimeCalendarImpDelegate::OnLButtonDownEx(CFWL_MsgMouse* pMsg) { |
| 67 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 68 m_pOwner->m_iLBtnPartStates = CFWL_PartState_Pressed; |
| 69 m_pOwner->PrevMonth(); |
| 70 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 71 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 72 m_pOwner->m_iRBtnPartStates |= CFWL_PartState_Pressed; |
| 73 m_pOwner->NextMonth(); |
| 74 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 75 } else if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 76 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == |
| 77 0) { |
| 78 m_pOwner->JumpToToday(); |
| 79 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 80 } |
| 81 } else { |
| 82 IFWL_DateTimePicker* pIPicker = |
| 83 static_cast<IFWL_DateTimePicker*>(m_pOwner->m_pOuter); |
| 84 if (pIPicker->IsMonthCalendarShowed()) { |
| 85 m_bFlag = 1; |
| 86 } |
| 87 } |
| 88 } |
| 89 |
| 90 void CFWL_DateTimeCalendarImpDelegate::OnLButtonUpEx(CFWL_MsgMouse* pMsg) { |
| 91 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { |
| 92 return DisForm_OnLButtonUpEx(pMsg); |
| 93 } |
| 94 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 95 m_pOwner->m_iLBtnPartStates = 0; |
| 96 m_pOwner->Repaint(&m_pOwner->m_rtLBtn); |
| 97 return; |
| 98 } |
| 99 if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 100 m_pOwner->m_iRBtnPartStates = 0; |
| 101 m_pOwner->Repaint(&m_pOwner->m_rtRBtn); |
| 102 return; |
| 103 } |
| 104 if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 105 return; |
| 106 } |
| 107 int32_t iOldSel = 0; |
| 108 if (m_pOwner->m_arrSelDays.GetSize() > 0) { |
| 109 iOldSel = m_pOwner->m_arrSelDays[0]; |
| 110 } |
| 111 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 112 CFX_RectF rt; |
| 113 IFWL_DateTimePicker* pIPicker = |
| 114 static_cast<IFWL_DateTimePicker*>(m_pOwner->m_pOuter); |
| 115 pIPicker->m_pForm->GetWidgetRect(rt); |
| 116 rt.Set(0, 0, rt.width, rt.height); |
| 117 if (iCurSel > 0) { |
| 118 FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); |
| 119 CFX_RectF rtInvalidate(lpDatesInfo->rect); |
| 120 if (iOldSel > 0 && iOldSel <= m_pOwner->m_arrDates.GetSize()) { |
| 121 lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); |
| 122 rtInvalidate.Union(lpDatesInfo->rect); |
| 123 } |
| 124 m_pOwner->AddSelDay(iCurSel); |
| 125 if (!m_pOwner->m_pOuter) |
| 126 return; |
| 127 pIPicker->ProcessSelChanged(m_pOwner->m_iCurYear, m_pOwner->m_iCurMonth, |
| 128 iCurSel); |
| 129 pIPicker->ShowMonthCalendar(FALSE); |
| 130 } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { |
| 131 pIPicker->ShowMonthCalendar(FALSE); |
| 132 } |
| 133 m_bFlag = 0; |
| 134 } |
| 135 |
| 136 void CFWL_DateTimeCalendarImpDelegate::OnMouseMoveEx(CFWL_MsgMouse* pMsg) { |
| 137 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) { |
| 138 return; |
| 139 } |
| 140 FX_BOOL bRepaint = FALSE; |
| 141 CFX_RectF rtInvalidate; |
| 142 rtInvalidate.Set(0, 0, 0, 0); |
| 143 if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 144 int32_t iHover = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 145 bRepaint = m_pOwner->m_iHovered != iHover; |
| 146 if (bRepaint) { |
| 147 if (m_pOwner->m_iHovered > 0) { |
| 148 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); |
| 149 } |
| 150 if (iHover > 0) { |
| 151 CFX_RectF rtDay; |
| 152 m_pOwner->GetDayRect(iHover, rtDay); |
| 153 if (rtInvalidate.IsEmpty()) { |
| 154 rtInvalidate = rtDay; |
| 155 } else { |
| 156 rtInvalidate.Union(rtDay); |
| 157 } |
| 158 } |
| 159 } |
| 160 m_pOwner->m_iHovered = iHover; |
| 161 CFWL_Event_DtpHoverChanged ev; |
| 162 ev.hoverday = iHover; |
| 163 m_pOwner->DispatchEvent(&ev); |
| 164 } else { |
| 165 bRepaint = m_pOwner->m_iHovered > 0; |
| 166 if (bRepaint) { |
| 167 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); |
| 168 } |
| 169 m_pOwner->m_iHovered = -1; |
| 170 } |
| 171 if (bRepaint && !rtInvalidate.IsEmpty()) { |
| 172 m_pOwner->Repaint(&rtInvalidate); |
| 173 } |
| 174 } |
| 175 |
| 176 void CFWL_DateTimeCalendarImpDelegate::DisForm_OnProcessMessage( |
| 177 CFWL_Message* pMessage) { |
| 178 if (pMessage->GetClassID() == CFWL_MessageType::Mouse) { |
| 179 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 180 if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) { |
| 181 DisForm_OnLButtonUpEx(pMsg); |
| 182 return; |
| 183 } |
| 184 } |
| 185 CFWL_MonthCalendarImpDelegate::OnProcessMessage(pMessage); |
| 186 } |
| 187 |
| 188 void CFWL_DateTimeCalendarImpDelegate::DisForm_OnLButtonUpEx( |
| 189 CFWL_MsgMouse* pMsg) { |
| 190 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 191 m_pOwner->m_iLBtnPartStates = 0; |
| 192 m_pOwner->Repaint(&(m_pOwner->m_rtLBtn)); |
| 193 return; |
| 194 } |
| 195 if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 196 m_pOwner->m_iRBtnPartStates = 0; |
| 197 m_pOwner->Repaint(&(m_pOwner->m_rtRBtn)); |
| 198 return; |
| 199 } |
| 200 if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 201 return; |
| 202 } |
| 203 int32_t iOldSel = 0; |
| 204 if (m_pOwner->m_arrSelDays.GetSize() > 0) { |
| 205 iOldSel = m_pOwner->m_arrSelDays[0]; |
| 206 } |
| 207 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 208 if (iCurSel > 0) { |
| 209 FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); |
| 210 CFX_RectF rtInvalidate(lpDatesInfo->rect); |
| 211 if (iOldSel > 0 && iOldSel <= m_pOwner->m_arrDates.GetSize()) { |
| 212 lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); |
| 213 rtInvalidate.Union(lpDatesInfo->rect); |
| 214 } |
| 215 m_pOwner->AddSelDay(iCurSel); |
| 216 IFWL_DateTimePicker* pDateTime = |
| 217 static_cast<IFWL_DateTimePicker*>(m_pOwner->m_pOuter); |
| 218 pDateTime->ProcessSelChanged(m_pOwner->m_iCurYear, m_pOwner->m_iCurMonth, |
| 219 iCurSel); |
| 220 pDateTime->ShowMonthCalendar(FALSE); |
| 221 } |
| 222 } |
OLD | NEW |