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_monthcalendar.h" | 7 #include "xfa/fwl/core/ifwl_monthcalendar.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "third_party/base/ptr_util.h" | 11 #include "third_party/base/ptr_util.h" |
12 #include "xfa/fde/tto/fde_textout.h" | 12 #include "xfa/fde/tto/fde_textout.h" |
13 #include "xfa/fwl/core/cfwl_message.h" | 13 #include "xfa/fwl/core/cfwl_message.h" |
14 #include "xfa/fwl/core/cfwl_themebackground.h" | 14 #include "xfa/fwl/core/cfwl_themebackground.h" |
15 #include "xfa/fwl/core/cfwl_themetext.h" | 15 #include "xfa/fwl/core/cfwl_themetext.h" |
16 #include "xfa/fwl/core/fwl_noteimp.h" | 16 #include "xfa/fwl/core/fwl_noteimp.h" |
| 17 #include "xfa/fwl/core/ifwl_datetimepicker.h" |
| 18 #include "xfa/fwl/core/ifwl_formproxy.h" |
17 #include "xfa/fwl/core/ifwl_monthcalendar.h" | 19 #include "xfa/fwl/core/ifwl_monthcalendar.h" |
18 #include "xfa/fwl/core/ifwl_themeprovider.h" | 20 #include "xfa/fwl/core/ifwl_themeprovider.h" |
19 | 21 |
20 #define MONTHCAL_HSEP_HEIGHT 1 | 22 #define MONTHCAL_HSEP_HEIGHT 1 |
21 #define MONTHCAL_VSEP_WIDTH 1 | 23 #define MONTHCAL_VSEP_WIDTH 1 |
22 #define MONTHCAL_HMARGIN 3 | 24 #define MONTHCAL_HMARGIN 3 |
23 #define MONTHCAL_VMARGIN 2 | 25 #define MONTHCAL_VMARGIN 2 |
24 #define MONTHCAL_ROWS 9 | 26 #define MONTHCAL_ROWS 9 |
25 #define MONTHCAL_COLUMNS 7 | 27 #define MONTHCAL_COLUMNS 7 |
26 #define MONTHCAL_HEADER_BTN_VMARGIN 7 | 28 #define MONTHCAL_HEADER_BTN_VMARGIN 7 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 m_bInit(false), | 128 m_bInit(false), |
127 m_pDateTime(new CFX_DateTime), | 129 m_pDateTime(new CFX_DateTime), |
128 m_iCurYear(2011), | 130 m_iCurYear(2011), |
129 m_iCurMonth(1), | 131 m_iCurMonth(1), |
130 m_iYear(2011), | 132 m_iYear(2011), |
131 m_iMonth(1), | 133 m_iMonth(1), |
132 m_iDay(1), | 134 m_iDay(1), |
133 m_iHovered(-1), | 135 m_iHovered(-1), |
134 m_iLBtnPartStates(CFWL_PartState_Normal), | 136 m_iLBtnPartStates(CFWL_PartState_Normal), |
135 m_iRBtnPartStates(CFWL_PartState_Normal), | 137 m_iRBtnPartStates(CFWL_PartState_Normal), |
136 m_iMaxSel(1) { | 138 m_iMaxSel(1), |
| 139 m_bFlag(false) { |
137 m_rtHead.Reset(); | 140 m_rtHead.Reset(); |
138 m_rtWeek.Reset(); | 141 m_rtWeek.Reset(); |
139 m_rtLBtn.Reset(); | 142 m_rtLBtn.Reset(); |
140 m_rtRBtn.Reset(); | 143 m_rtRBtn.Reset(); |
141 m_rtDates.Reset(); | 144 m_rtDates.Reset(); |
142 m_rtHSep.Reset(); | 145 m_rtHSep.Reset(); |
143 m_rtHeadText.Reset(); | 146 m_rtHeadText.Reset(); |
144 m_rtToday.Reset(); | 147 m_rtToday.Reset(); |
145 m_rtTodayFlag.Reset(); | 148 m_rtTodayFlag.Reset(); |
146 m_rtClient.Reset(); | 149 m_rtClient.Reset(); |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 return true; | 1012 return true; |
1010 } | 1013 } |
1011 | 1014 |
1012 void IFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { | 1015 void IFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { |
1013 if (!pMessage) | 1016 if (!pMessage) |
1014 return; | 1017 return; |
1015 | 1018 |
1016 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 1019 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
1017 switch (dwMsgCode) { | 1020 switch (dwMsgCode) { |
1018 case CFWL_MessageType::SetFocus: | 1021 case CFWL_MessageType::SetFocus: |
1019 OnFocusChanged(pMessage, true); | |
1020 break; | |
1021 case CFWL_MessageType::KillFocus: | 1022 case CFWL_MessageType::KillFocus: |
1022 OnFocusChanged(pMessage, false); | 1023 GetOuter()->GetDelegate()->OnProcessMessage(pMessage); |
1023 break; | 1024 break; |
1024 case CFWL_MessageType::Key: | 1025 case CFWL_MessageType::Key: |
1025 break; | 1026 break; |
1026 case CFWL_MessageType::Mouse: { | 1027 case CFWL_MessageType::Mouse: { |
1027 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | 1028 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); |
1028 switch (pMouse->m_dwCmd) { | 1029 switch (pMouse->m_dwCmd) { |
1029 case FWL_MouseCommand::LeftButtonDown: | 1030 case FWL_MouseCommand::LeftButtonDown: |
1030 OnLButtonDown(pMouse); | 1031 OnLButtonDown(pMouse); |
1031 break; | 1032 break; |
1032 case FWL_MouseCommand::LeftButtonUp: | 1033 case FWL_MouseCommand::LeftButtonUp: |
(...skipping 14 matching lines...) Expand all Loading... |
1047 break; | 1048 break; |
1048 } | 1049 } |
1049 IFWL_Widget::OnProcessMessage(pMessage); | 1050 IFWL_Widget::OnProcessMessage(pMessage); |
1050 } | 1051 } |
1051 | 1052 |
1052 void IFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, | 1053 void IFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, |
1053 const CFX_Matrix* pMatrix) { | 1054 const CFX_Matrix* pMatrix) { |
1054 DrawWidget(pGraphics, pMatrix); | 1055 DrawWidget(pGraphics, pMatrix); |
1055 } | 1056 } |
1056 | 1057 |
1057 void IFWL_MonthCalendar::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | |
1058 if (bSet) | |
1059 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
1060 else | |
1061 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
1062 | |
1063 Repaint(&m_rtClient); | |
1064 } | |
1065 | |
1066 void IFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 1058 void IFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
1067 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1059 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
1068 m_iLBtnPartStates = CFWL_PartState_Pressed; | 1060 m_iLBtnPartStates = CFWL_PartState_Pressed; |
1069 PrevMonth(); | 1061 PrevMonth(); |
1070 Repaint(&m_rtClient); | 1062 Repaint(&m_rtClient); |
1071 } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1063 } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
1072 m_iRBtnPartStates |= CFWL_PartState_Pressed; | 1064 m_iRBtnPartStates |= CFWL_PartState_Pressed; |
1073 NextMonth(); | 1065 NextMonth(); |
1074 Repaint(&m_rtClient); | 1066 Repaint(&m_rtClient); |
1075 } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1067 } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { |
1076 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { | 1068 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { |
1077 JumpToToday(); | 1069 JumpToToday(); |
1078 Repaint(&m_rtClient); | 1070 Repaint(&m_rtClient); |
1079 } | 1071 } |
1080 } else { | 1072 } else { |
1081 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect)) { | 1073 IFWL_DateTimePicker* pIPicker = static_cast<IFWL_DateTimePicker*>(m_pOuter); |
1082 int32_t iOldSel = 0; | 1074 if (pIPicker->IsMonthCalendarShowed()) |
1083 if (m_arrSelDays.GetSize() <= 0) | 1075 m_bFlag = 1; |
1084 return; | |
1085 iOldSel = m_arrSelDays[0]; | |
1086 | |
1087 int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
1088 bool bSelChanged = iCurSel > 0 && iCurSel != iOldSel; | |
1089 if (bSelChanged) { | |
1090 FWL_DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); | |
1091 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
1092 if (iOldSel > 0) { | |
1093 lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); | |
1094 rtInvalidate.Union(lpDatesInfo->rect); | |
1095 } | |
1096 AddSelDay(iCurSel); | |
1097 CFWL_EvtClick wmClick; | |
1098 wmClick.m_pSrcTarget = this; | |
1099 DispatchEvent(&wmClick); | |
1100 CFWL_EventMcdDateChanged wmDateSelected; | |
1101 wmDateSelected.m_iStartDay = iCurSel; | |
1102 wmDateSelected.m_iEndDay = iCurSel; | |
1103 wmDateSelected.m_iOldMonth = m_iCurMonth; | |
1104 wmDateSelected.m_iOldYear = m_iCurYear; | |
1105 wmDateSelected.m_pSrcTarget = this; | |
1106 DispatchEvent(&wmDateSelected); | |
1107 Repaint(&rtInvalidate); | |
1108 } | |
1109 } | |
1110 } | 1076 } |
1111 } | 1077 } |
1112 | 1078 |
1113 void IFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 1079 void IFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 1080 if (m_pWidgetMgr->IsFormDisabled()) |
| 1081 return DisForm_OnLButtonUp(pMsg); |
| 1082 |
1114 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1083 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
1115 m_iLBtnPartStates = 0; | 1084 m_iLBtnPartStates = 0; |
1116 Repaint(&m_rtLBtn); | 1085 Repaint(&m_rtLBtn); |
1117 } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1086 return; |
| 1087 } |
| 1088 if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
1118 m_iRBtnPartStates = 0; | 1089 m_iRBtnPartStates = 0; |
1119 Repaint(&m_rtRBtn); | 1090 Repaint(&m_rtRBtn); |
1120 } else if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1091 return; |
1121 int32_t iDay = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | 1092 } |
1122 if (iDay != -1) | 1093 if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) |
1123 AddSelDay(iDay); | 1094 return; |
| 1095 |
| 1096 int32_t iOldSel = 0; |
| 1097 if (m_arrSelDays.GetSize() > 0) |
| 1098 iOldSel = m_arrSelDays[0]; |
| 1099 |
| 1100 int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 1101 CFX_RectF rt; |
| 1102 IFWL_DateTimePicker* pIPicker = static_cast<IFWL_DateTimePicker*>(m_pOuter); |
| 1103 pIPicker->GetFormProxy()->GetWidgetRect(rt); |
| 1104 rt.Set(0, 0, rt.width, rt.height); |
| 1105 if (iCurSel > 0) { |
| 1106 FWL_DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); |
| 1107 CFX_RectF rtInvalidate(lpDatesInfo->rect); |
| 1108 if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { |
| 1109 lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); |
| 1110 rtInvalidate.Union(lpDatesInfo->rect); |
| 1111 } |
| 1112 AddSelDay(iCurSel); |
| 1113 if (!m_pOuter) |
| 1114 return; |
| 1115 |
| 1116 pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); |
| 1117 pIPicker->ShowMonthCalendar(false); |
| 1118 } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { |
| 1119 pIPicker->ShowMonthCalendar(false); |
| 1120 } |
| 1121 m_bFlag = 0; |
| 1122 } |
| 1123 |
| 1124 void IFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 1125 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 1126 m_iLBtnPartStates = 0; |
| 1127 Repaint(&(m_rtLBtn)); |
| 1128 return; |
| 1129 } |
| 1130 if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 1131 m_iRBtnPartStates = 0; |
| 1132 Repaint(&(m_rtRBtn)); |
| 1133 return; |
| 1134 } |
| 1135 if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 1136 return; |
| 1137 |
| 1138 int32_t iOldSel = 0; |
| 1139 if (m_arrSelDays.GetSize() > 0) |
| 1140 iOldSel = m_arrSelDays[0]; |
| 1141 |
| 1142 int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 1143 if (iCurSel > 0) { |
| 1144 FWL_DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); |
| 1145 CFX_RectF rtInvalidate(lpDatesInfo->rect); |
| 1146 if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { |
| 1147 lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); |
| 1148 rtInvalidate.Union(lpDatesInfo->rect); |
| 1149 } |
| 1150 AddSelDay(iCurSel); |
| 1151 IFWL_DateTimePicker* pDateTime = |
| 1152 static_cast<IFWL_DateTimePicker*>(m_pOuter); |
| 1153 pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); |
| 1154 pDateTime->ShowMonthCalendar(false); |
1124 } | 1155 } |
1125 } | 1156 } |
1126 | 1157 |
1127 void IFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { | 1158 void IFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { |
1128 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) | 1159 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) |
1129 return; | 1160 return; |
1130 | 1161 |
1131 bool bRepaint = false; | 1162 bool bRepaint = false; |
1132 CFX_RectF rtInvalidate; | 1163 CFX_RectF rtInvalidate; |
1133 rtInvalidate.Set(0, 0, 0, 0); | 1164 rtInvalidate.Set(0, 0, 0, 0); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 uint32_t dwSt, | 1206 uint32_t dwSt, |
1176 CFX_RectF rc, | 1207 CFX_RectF rc, |
1177 CFX_WideString& wsday) | 1208 CFX_WideString& wsday) |
1178 : iDay(day), | 1209 : iDay(day), |
1179 iDayOfWeek(dayofweek), | 1210 iDayOfWeek(dayofweek), |
1180 dwStates(dwSt), | 1211 dwStates(dwSt), |
1181 rect(rc), | 1212 rect(rc), |
1182 wsDay(wsday) {} | 1213 wsDay(wsday) {} |
1183 | 1214 |
1184 FWL_DATEINFO::~FWL_DATEINFO() {} | 1215 FWL_DATEINFO::~FWL_DATEINFO() {} |
OLD | NEW |