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