| 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/basewidget/fwl_monthcalendarimp.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "xfa/fde/tto/fde_textout.h" | |
| 12 #include "xfa/fwl/basewidget/ifwl_monthcalendar.h" | |
| 13 #include "xfa/fwl/core/cfwl_message.h" | |
| 14 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 15 #include "xfa/fwl/core/cfwl_themetext.h" | |
| 16 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 17 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 18 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 19 | |
| 20 #define MONTHCAL_HSEP_HEIGHT 1 | |
| 21 #define MONTHCAL_VSEP_WIDTH 1 | |
| 22 #define MONTHCAL_HMARGIN 3 | |
| 23 #define MONTHCAL_VMARGIN 2 | |
| 24 #define MONTHCAL_ROWS 9 | |
| 25 #define MONTHCAL_COLUMNS 7 | |
| 26 #define MONTHCAL_HEADER_BTN_VMARGIN 7 | |
| 27 #define MONTHCAL_HEADER_BTN_HMARGIN 5 | |
| 28 | |
| 29 namespace { | |
| 30 | |
| 31 CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, | |
| 32 CFWL_ThemePart& params, | |
| 33 uint32_t day) { | |
| 34 ASSERT(day < 7); | |
| 35 | |
| 36 if (day == 0) { | |
| 37 return static_cast<CFX_WideString*>( | |
| 38 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); | |
| 39 } | |
| 40 if (day == 1) { | |
| 41 return static_cast<CFX_WideString*>( | |
| 42 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); | |
| 43 } | |
| 44 if (day == 2) { | |
| 45 return static_cast<CFX_WideString*>( | |
| 46 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); | |
| 47 } | |
| 48 if (day == 3) { | |
| 49 return static_cast<CFX_WideString*>( | |
| 50 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); | |
| 51 } | |
| 52 if (day == 4) { | |
| 53 return static_cast<CFX_WideString*>( | |
| 54 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); | |
| 55 } | |
| 56 if (day == 5) { | |
| 57 return static_cast<CFX_WideString*>( | |
| 58 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); | |
| 59 } | |
| 60 | |
| 61 return static_cast<CFX_WideString*>( | |
| 62 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); | |
| 63 } | |
| 64 | |
| 65 CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, | |
| 66 CFWL_ThemePart& params, | |
| 67 uint32_t month) { | |
| 68 ASSERT(month < 12); | |
| 69 | |
| 70 if (month == 0) { | |
| 71 return static_cast<CFX_WideString*>( | |
| 72 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); | |
| 73 } | |
| 74 if (month == 1) { | |
| 75 return static_cast<CFX_WideString*>( | |
| 76 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); | |
| 77 } | |
| 78 if (month == 2) { | |
| 79 return static_cast<CFX_WideString*>( | |
| 80 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); | |
| 81 } | |
| 82 if (month == 3) { | |
| 83 return static_cast<CFX_WideString*>( | |
| 84 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); | |
| 85 } | |
| 86 if (month == 4) { | |
| 87 return static_cast<CFX_WideString*>( | |
| 88 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); | |
| 89 } | |
| 90 if (month == 5) { | |
| 91 return static_cast<CFX_WideString*>( | |
| 92 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); | |
| 93 } | |
| 94 if (month == 6) { | |
| 95 return static_cast<CFX_WideString*>( | |
| 96 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); | |
| 97 } | |
| 98 if (month == 7) { | |
| 99 return static_cast<CFX_WideString*>( | |
| 100 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); | |
| 101 } | |
| 102 if (month == 8) { | |
| 103 return static_cast<CFX_WideString*>( | |
| 104 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); | |
| 105 } | |
| 106 if (month == 9) { | |
| 107 return static_cast<CFX_WideString*>( | |
| 108 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); | |
| 109 } | |
| 110 if (month == 10) { | |
| 111 return static_cast<CFX_WideString*>( | |
| 112 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); | |
| 113 } | |
| 114 | |
| 115 return static_cast<CFX_WideString*>( | |
| 116 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); | |
| 117 } | |
| 118 | |
| 119 } // namespace | |
| 120 | |
| 121 // static | |
| 122 IFWL_MonthCalendar* IFWL_MonthCalendar::Create( | |
| 123 const CFWL_WidgetImpProperties& properties, | |
| 124 IFWL_Widget* pOuter) { | |
| 125 IFWL_MonthCalendar* pMonthCalendar = new IFWL_MonthCalendar; | |
| 126 CFWL_MonthCalendarImp* pMonthCalendarImpl = | |
| 127 new CFWL_MonthCalendarImp(properties, pOuter); | |
| 128 pMonthCalendar->SetImpl(pMonthCalendarImpl); | |
| 129 pMonthCalendarImpl->SetInterface(pMonthCalendar); | |
| 130 return pMonthCalendar; | |
| 131 } | |
| 132 IFWL_MonthCalendar::IFWL_MonthCalendar() {} | |
| 133 int32_t IFWL_MonthCalendar::CountSelect() { | |
| 134 return static_cast<CFWL_MonthCalendarImp*>(GetImpl())->CountSelect(); | |
| 135 } | |
| 136 FX_BOOL IFWL_MonthCalendar::GetSelect(int32_t& iYear, | |
| 137 int32_t& iMonth, | |
| 138 int32_t& iDay, | |
| 139 int32_t nIndex) { | |
| 140 return static_cast<CFWL_MonthCalendarImp*>(GetImpl()) | |
| 141 ->GetSelect(iYear, iMonth, iDay, nIndex); | |
| 142 } | |
| 143 FX_BOOL IFWL_MonthCalendar::SetSelect(int32_t iYear, | |
| 144 int32_t iMonth, | |
| 145 int32_t iDay) { | |
| 146 return static_cast<CFWL_MonthCalendarImp*>(GetImpl()) | |
| 147 ->SetSelect(iYear, iMonth, iDay); | |
| 148 } | |
| 149 | |
| 150 CFWL_MonthCalendarImp::CFWL_MonthCalendarImp( | |
| 151 const CFWL_WidgetImpProperties& properties, | |
| 152 IFWL_Widget* pOuter) | |
| 153 : CFWL_WidgetImp(properties, pOuter), | |
| 154 m_bInit(FALSE), | |
| 155 m_pDateTime(new CFX_DateTime), | |
| 156 m_iCurYear(2011), | |
| 157 m_iCurMonth(1), | |
| 158 m_iYear(2011), | |
| 159 m_iMonth(1), | |
| 160 m_iDay(1), | |
| 161 m_iHovered(-1), | |
| 162 m_iLBtnPartStates(CFWL_PartState_Normal), | |
| 163 m_iRBtnPartStates(CFWL_PartState_Normal), | |
| 164 m_iMaxSel(1) { | |
| 165 m_rtHead.Reset(); | |
| 166 m_rtWeek.Reset(); | |
| 167 m_rtLBtn.Reset(); | |
| 168 m_rtRBtn.Reset(); | |
| 169 m_rtDates.Reset(); | |
| 170 m_rtHSep.Reset(); | |
| 171 m_rtHeadText.Reset(); | |
| 172 m_rtToday.Reset(); | |
| 173 m_rtTodayFlag.Reset(); | |
| 174 m_rtClient.Reset(); | |
| 175 m_rtWeekNum.Reset(); | |
| 176 m_rtWeekNumSep.Reset(); | |
| 177 } | |
| 178 | |
| 179 CFWL_MonthCalendarImp::~CFWL_MonthCalendarImp() { | |
| 180 ClearDateItem(); | |
| 181 m_arrSelDays.RemoveAll(); | |
| 182 } | |
| 183 | |
| 184 FWL_Error CFWL_MonthCalendarImp::GetClassName(CFX_WideString& wsClass) const { | |
| 185 wsClass = FWL_CLASS_MonthCalendar; | |
| 186 return FWL_Error::Succeeded; | |
| 187 } | |
| 188 | |
| 189 FWL_Type CFWL_MonthCalendarImp::GetClassID() const { | |
| 190 return FWL_Type::MonthCalendar; | |
| 191 } | |
| 192 | |
| 193 FWL_Error CFWL_MonthCalendarImp::Initialize() { | |
| 194 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 195 return FWL_Error::Indefinite; | |
| 196 | |
| 197 m_pDelegate = new CFWL_MonthCalendarImpDelegate(this); | |
| 198 return FWL_Error::Succeeded; | |
| 199 } | |
| 200 | |
| 201 FWL_Error CFWL_MonthCalendarImp::Finalize() { | |
| 202 delete m_pDelegate; | |
| 203 m_pDelegate = nullptr; | |
| 204 return CFWL_WidgetImp::Finalize(); | |
| 205 } | |
| 206 FWL_Error CFWL_MonthCalendarImp::GetWidgetRect(CFX_RectF& rect, | |
| 207 FX_BOOL bAutoSize) { | |
| 208 if (bAutoSize) { | |
| 209 CFX_SizeF fs = CalcSize(TRUE); | |
| 210 rect.Set(0, 0, fs.x, fs.y); | |
| 211 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 212 } else { | |
| 213 rect = m_pProperties->m_rtWidget; | |
| 214 } | |
| 215 return FWL_Error::Succeeded; | |
| 216 } | |
| 217 FWL_Error CFWL_MonthCalendarImp::Update() { | |
| 218 if (IsLocked()) { | |
| 219 return FWL_Error::Indefinite; | |
| 220 } | |
| 221 if (!m_pProperties->m_pThemeProvider) { | |
| 222 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 223 } | |
| 224 GetCapValue(); | |
| 225 if (!m_bInit) { | |
| 226 m_bInit = InitDate(); | |
| 227 } | |
| 228 ClearDateItem(); | |
| 229 ReSetDateItem(); | |
| 230 LayOut(); | |
| 231 return FWL_Error::Succeeded; | |
| 232 } | |
| 233 FWL_Error CFWL_MonthCalendarImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 234 const CFX_Matrix* pMatrix) { | |
| 235 if (!pGraphics) | |
| 236 return FWL_Error::Indefinite; | |
| 237 if (!m_pProperties->m_pThemeProvider) { | |
| 238 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 239 } | |
| 240 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 241 if (HasBorder()) { | |
| 242 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
| 243 } | |
| 244 if (HasEdge()) { | |
| 245 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
| 246 } | |
| 247 DrawBkground(pGraphics, pTheme, pMatrix); | |
| 248 DrawHeadBK(pGraphics, pTheme, pMatrix); | |
| 249 DrawLButton(pGraphics, pTheme, pMatrix); | |
| 250 DrawRButton(pGraphics, pTheme, pMatrix); | |
| 251 DrawSeperator(pGraphics, pTheme, pMatrix); | |
| 252 DrawDatesInBK(pGraphics, pTheme, pMatrix); | |
| 253 DrawDatesInCircle(pGraphics, pTheme, pMatrix); | |
| 254 DrawCaption(pGraphics, pTheme, pMatrix); | |
| 255 DrawWeek(pGraphics, pTheme, pMatrix); | |
| 256 DrawDatesIn(pGraphics, pTheme, pMatrix); | |
| 257 DrawDatesOut(pGraphics, pTheme, pMatrix); | |
| 258 DrawToday(pGraphics, pTheme, pMatrix); | |
| 259 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { | |
| 260 DrawWeekNumberSep(pGraphics, pTheme, pMatrix); | |
| 261 DrawWeekNumber(pGraphics, pTheme, pMatrix); | |
| 262 } | |
| 263 return FWL_Error::Succeeded; | |
| 264 } | |
| 265 int32_t CFWL_MonthCalendarImp::CountSelect() { | |
| 266 return m_arrSelDays.GetSize(); | |
| 267 } | |
| 268 FX_BOOL CFWL_MonthCalendarImp::GetSelect(int32_t& iYear, | |
| 269 int32_t& iMonth, | |
| 270 int32_t& iDay, | |
| 271 int32_t nIndex) { | |
| 272 if (nIndex >= m_arrSelDays.GetSize()) { | |
| 273 return FALSE; | |
| 274 } | |
| 275 iYear = m_iCurYear; | |
| 276 iMonth = m_iCurMonth; | |
| 277 iDay = m_arrSelDays[nIndex]; | |
| 278 return TRUE; | |
| 279 } | |
| 280 FX_BOOL CFWL_MonthCalendarImp::SetSelect(int32_t iYear, | |
| 281 int32_t iMonth, | |
| 282 int32_t iDay) { | |
| 283 ChangeToMonth(iYear, iMonth); | |
| 284 return AddSelDay(iDay); | |
| 285 } | |
| 286 void CFWL_MonthCalendarImp::DrawBkground(CFX_Graphics* pGraphics, | |
| 287 IFWL_ThemeProvider* pTheme, | |
| 288 const CFX_Matrix* pMatrix) { | |
| 289 CFWL_ThemeBackground params; | |
| 290 params.m_pWidget = m_pInterface; | |
| 291 params.m_iPart = CFWL_Part::Background; | |
| 292 params.m_pGraphics = pGraphics; | |
| 293 params.m_dwStates = CFWL_PartState_Normal; | |
| 294 params.m_rtPart = m_rtClient; | |
| 295 if (pMatrix) { | |
| 296 params.m_matrix.Concat(*pMatrix); | |
| 297 } | |
| 298 pTheme->DrawBackground(¶ms); | |
| 299 } | |
| 300 void CFWL_MonthCalendarImp::DrawHeadBK(CFX_Graphics* pGraphics, | |
| 301 IFWL_ThemeProvider* pTheme, | |
| 302 const CFX_Matrix* pMatrix) { | |
| 303 CFWL_ThemeBackground params; | |
| 304 params.m_pWidget = m_pInterface; | |
| 305 params.m_iPart = CFWL_Part::Header; | |
| 306 params.m_pGraphics = pGraphics; | |
| 307 params.m_dwStates = CFWL_PartState_Normal; | |
| 308 params.m_rtPart = m_rtHead; | |
| 309 if (pMatrix) { | |
| 310 params.m_matrix.Concat(*pMatrix); | |
| 311 } | |
| 312 pTheme->DrawBackground(¶ms); | |
| 313 } | |
| 314 void CFWL_MonthCalendarImp::DrawLButton(CFX_Graphics* pGraphics, | |
| 315 IFWL_ThemeProvider* pTheme, | |
| 316 const CFX_Matrix* pMatrix) { | |
| 317 CFWL_ThemeBackground params; | |
| 318 params.m_pWidget = m_pInterface; | |
| 319 params.m_iPart = CFWL_Part::LBtn; | |
| 320 params.m_pGraphics = pGraphics; | |
| 321 params.m_dwStates = m_iLBtnPartStates; | |
| 322 params.m_rtPart = m_rtLBtn; | |
| 323 if (pMatrix) { | |
| 324 params.m_matrix.Concat(*pMatrix); | |
| 325 } | |
| 326 pTheme->DrawBackground(¶ms); | |
| 327 } | |
| 328 void CFWL_MonthCalendarImp::DrawRButton(CFX_Graphics* pGraphics, | |
| 329 IFWL_ThemeProvider* pTheme, | |
| 330 const CFX_Matrix* pMatrix) { | |
| 331 CFWL_ThemeBackground params; | |
| 332 params.m_pWidget = m_pInterface; | |
| 333 params.m_iPart = CFWL_Part::RBtn; | |
| 334 params.m_pGraphics = pGraphics; | |
| 335 params.m_dwStates = m_iRBtnPartStates; | |
| 336 params.m_rtPart = m_rtRBtn; | |
| 337 if (pMatrix) { | |
| 338 params.m_matrix.Concat(*pMatrix); | |
| 339 } | |
| 340 pTheme->DrawBackground(¶ms); | |
| 341 } | |
| 342 void CFWL_MonthCalendarImp::DrawCaption(CFX_Graphics* pGraphics, | |
| 343 IFWL_ThemeProvider* pTheme, | |
| 344 const CFX_Matrix* pMatrix) { | |
| 345 CFWL_ThemeText textParam; | |
| 346 textParam.m_pWidget = m_pInterface; | |
| 347 textParam.m_iPart = CFWL_Part::Caption; | |
| 348 textParam.m_dwStates = CFWL_PartState_Normal; | |
| 349 textParam.m_pGraphics = pGraphics; | |
| 350 int32_t iYear; | |
| 351 int32_t iMonth; | |
| 352 iYear = m_iCurYear; | |
| 353 iMonth = m_iCurMonth; | |
| 354 CFX_WideString wsCation; | |
| 355 GetHeadText(iYear, iMonth, wsCation); | |
| 356 textParam.m_wsText = wsCation; | |
| 357 m_szHead = CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider); | |
| 358 CalcHeadSize(); | |
| 359 textParam.m_rtPart = m_rtHeadText; | |
| 360 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 361 textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 362 if (pMatrix) { | |
| 363 textParam.m_matrix.Concat(*pMatrix); | |
| 364 } | |
| 365 pTheme->DrawText(&textParam); | |
| 366 } | |
| 367 void CFWL_MonthCalendarImp::DrawSeperator(CFX_Graphics* pGraphics, | |
| 368 IFWL_ThemeProvider* pTheme, | |
| 369 const CFX_Matrix* pMatrix) { | |
| 370 CFWL_ThemeBackground params; | |
| 371 params.m_pWidget = m_pInterface; | |
| 372 params.m_iPart = CFWL_Part::HSeparator; | |
| 373 params.m_pGraphics = pGraphics; | |
| 374 params.m_dwStates = CFWL_PartState_Normal; | |
| 375 params.m_rtPart = m_rtHSep; | |
| 376 if (pMatrix) { | |
| 377 params.m_matrix.Concat(*pMatrix); | |
| 378 } | |
| 379 pTheme->DrawBackground(¶ms); | |
| 380 } | |
| 381 void CFWL_MonthCalendarImp::DrawDatesInBK(CFX_Graphics* pGraphics, | |
| 382 IFWL_ThemeProvider* pTheme, | |
| 383 const CFX_Matrix* pMatrix) { | |
| 384 CFWL_ThemeBackground params; | |
| 385 params.m_pWidget = m_pInterface; | |
| 386 params.m_iPart = CFWL_Part::DateInBK; | |
| 387 params.m_pGraphics = pGraphics; | |
| 388 if (pMatrix) { | |
| 389 params.m_matrix.Concat(*pMatrix); | |
| 390 } | |
| 391 int32_t iCount = m_arrDates.GetSize(); | |
| 392 for (int32_t j = 0; j < iCount; j++) { | |
| 393 FWL_DATEINFO* pDataInfo = m_arrDates.GetAt(j); | |
| 394 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { | |
| 395 params.m_dwStates |= CFWL_PartState_Selected; | |
| 396 if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == | |
| 397 0) && | |
| 398 pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { | |
| 399 params.m_dwStates |= CFWL_PartState_Flagged; | |
| 400 } | |
| 401 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) { | |
| 402 params.m_dwStates |= CFWL_PartState_Focused; | |
| 403 } | |
| 404 } else if (j == m_iHovered - 1) { | |
| 405 params.m_dwStates |= CFWL_PartState_Hovered; | |
| 406 } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { | |
| 407 params.m_dwStates = CFWL_PartState_Flagged; | |
| 408 pTheme->DrawBackground(¶ms); | |
| 409 } | |
| 410 params.m_rtPart = pDataInfo->rect; | |
| 411 pTheme->DrawBackground(¶ms); | |
| 412 params.m_dwStates = 0; | |
| 413 } | |
| 414 } | |
| 415 void CFWL_MonthCalendarImp::DrawWeek(CFX_Graphics* pGraphics, | |
| 416 IFWL_ThemeProvider* pTheme, | |
| 417 const CFX_Matrix* pMatrix) { | |
| 418 CFWL_ThemeText params; | |
| 419 params.m_pWidget = m_pInterface; | |
| 420 params.m_iPart = CFWL_Part::Week; | |
| 421 params.m_pGraphics = pGraphics; | |
| 422 params.m_dwStates = CFWL_PartState_Normal; | |
| 423 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 424 CFX_RectF rtDayOfWeek; | |
| 425 if (pMatrix) { | |
| 426 params.m_matrix.Concat(*pMatrix); | |
| 427 } | |
| 428 for (int32_t i = 0; i < 7; i++) { | |
| 429 rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), | |
| 430 m_rtWeek.top, m_szCell.x, m_szCell.y); | |
| 431 params.m_rtPart = rtDayOfWeek; | |
| 432 params.m_wsText = *GetCapacityForDay(pTheme, params, i); | |
| 433 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 434 pTheme->DrawText(¶ms); | |
| 435 } | |
| 436 } | |
| 437 void CFWL_MonthCalendarImp::DrawWeekNumber(CFX_Graphics* pGraphics, | |
| 438 IFWL_ThemeProvider* pTheme, | |
| 439 const CFX_Matrix* pMatrix) { | |
| 440 CFWL_ThemeText params; | |
| 441 params.m_pWidget = m_pInterface; | |
| 442 params.m_iPart = CFWL_Part::WeekNum; | |
| 443 params.m_pGraphics = pGraphics; | |
| 444 params.m_dwStates = CFWL_PartState_Normal; | |
| 445 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
| 446 CFX_WideString wsWeekNum; | |
| 447 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 448 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 449 if (pMatrix) { | |
| 450 params.m_matrix.Concat(*pMatrix); | |
| 451 } | |
| 452 int32_t iWeekNum = 0; | |
| 453 int32_t iMonthNum = m_pDateTime->GetMonth(); | |
| 454 int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); | |
| 455 int32_t iTemp = 0; | |
| 456 FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; | |
| 457 FX_FLOAT fHStartPos = m_rtClient.left; | |
| 458 for (int32_t i = 1; i <= iDayNum; i += 7) { | |
| 459 iTemp++; | |
| 460 iWeekNum = CalWeekNumber(m_iCurYear, iMonthNum, i); | |
| 461 m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, | |
| 462 m_fWeekNumWid, m_fDateCellHei); | |
| 463 wsWeekNum.Format(L"%d", iWeekNum); | |
| 464 params.m_wsText = wsWeekNum; | |
| 465 params.m_rtPart = m_rtWeekNum; | |
| 466 pTheme->DrawText(¶ms); | |
| 467 } | |
| 468 } | |
| 469 void CFWL_MonthCalendarImp::DrawWeekNumberSep(CFX_Graphics* pGraphics, | |
| 470 IFWL_ThemeProvider* pTheme, | |
| 471 const CFX_Matrix* pMatrix) { | |
| 472 CFWL_ThemeBackground params; | |
| 473 params.m_pWidget = m_pInterface; | |
| 474 params.m_iPart = CFWL_Part::WeekNumSep; | |
| 475 params.m_pGraphics = pGraphics; | |
| 476 params.m_dwStates = CFWL_PartState_Normal; | |
| 477 params.m_rtPart = m_rtWeekNumSep; | |
| 478 if (pMatrix) { | |
| 479 params.m_matrix.Concat(*pMatrix); | |
| 480 } | |
| 481 pTheme->DrawBackground(¶ms); | |
| 482 } | |
| 483 void CFWL_MonthCalendarImp::DrawToday(CFX_Graphics* pGraphics, | |
| 484 IFWL_ThemeProvider* pTheme, | |
| 485 const CFX_Matrix* pMatrix) { | |
| 486 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) { | |
| 487 return; | |
| 488 } | |
| 489 CFWL_ThemeText params; | |
| 490 params.m_pWidget = m_pInterface; | |
| 491 params.m_iPart = CFWL_Part::Today; | |
| 492 params.m_pGraphics = pGraphics; | |
| 493 params.m_dwStates = CFWL_PartState_Normal; | |
| 494 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
| 495 CFX_WideString* wsDay = static_cast<CFX_WideString*>( | |
| 496 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); | |
| 497 CFX_WideString wsText; | |
| 498 GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); | |
| 499 params.m_wsText = *wsDay + wsText; | |
| 500 m_szToday = CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider); | |
| 501 CalcTodaySize(); | |
| 502 params.m_rtPart = m_rtToday; | |
| 503 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 504 if (pMatrix) { | |
| 505 params.m_matrix.Concat(*pMatrix); | |
| 506 } | |
| 507 pTheme->DrawText(¶ms); | |
| 508 } | |
| 509 void CFWL_MonthCalendarImp::DrawDatesIn(CFX_Graphics* pGraphics, | |
| 510 IFWL_ThemeProvider* pTheme, | |
| 511 const CFX_Matrix* pMatrix) { | |
| 512 CFWL_ThemeText params; | |
| 513 params.m_pWidget = m_pInterface; | |
| 514 params.m_iPart = CFWL_Part::DatesIn; | |
| 515 params.m_pGraphics = pGraphics; | |
| 516 params.m_dwStates = CFWL_PartState_Normal; | |
| 517 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 518 if (pMatrix) { | |
| 519 params.m_matrix.Concat(*pMatrix); | |
| 520 } | |
| 521 int32_t iCount = m_arrDates.GetSize(); | |
| 522 for (int32_t j = 0; j < iCount; j++) { | |
| 523 FWL_DATEINFO* pDataInfo = m_arrDates.GetAt(j); | |
| 524 params.m_wsText = pDataInfo->wsDay; | |
| 525 params.m_rtPart = pDataInfo->rect; | |
| 526 params.m_dwStates = pDataInfo->dwStates; | |
| 527 if (j + 1 == m_iHovered) { | |
| 528 params.m_dwStates |= CFWL_PartState_Hovered; | |
| 529 } | |
| 530 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 531 pTheme->DrawText(¶ms); | |
| 532 } | |
| 533 } | |
| 534 void CFWL_MonthCalendarImp::DrawDatesOut(CFX_Graphics* pGraphics, | |
| 535 IFWL_ThemeProvider* pTheme, | |
| 536 const CFX_Matrix* pMatrix) { | |
| 537 CFWL_ThemeText params; | |
| 538 params.m_pWidget = m_pInterface; | |
| 539 params.m_iPart = CFWL_Part::DatesOut; | |
| 540 params.m_pGraphics = pGraphics; | |
| 541 params.m_dwStates = CFWL_PartState_Normal; | |
| 542 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 543 if (pMatrix) { | |
| 544 params.m_matrix.Concat(*pMatrix); | |
| 545 } | |
| 546 pTheme->DrawText(¶ms); | |
| 547 } | |
| 548 void CFWL_MonthCalendarImp::DrawDatesInCircle(CFX_Graphics* pGraphics, | |
| 549 IFWL_ThemeProvider* pTheme, | |
| 550 const CFX_Matrix* pMatrix) { | |
| 551 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) { | |
| 552 return; | |
| 553 } | |
| 554 if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) { | |
| 555 return; | |
| 556 } | |
| 557 if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) { | |
| 558 return; | |
| 559 } | |
| 560 FWL_DATEINFO* pDate = m_arrDates[m_iDay - 1]; | |
| 561 if (!pDate) | |
| 562 return; | |
| 563 CFWL_ThemeBackground params; | |
| 564 params.m_pWidget = m_pInterface; | |
| 565 params.m_iPart = CFWL_Part::DateInCircle; | |
| 566 params.m_pGraphics = pGraphics; | |
| 567 params.m_rtPart = pDate->rect; | |
| 568 params.m_dwStates = CFWL_PartState_Normal; | |
| 569 if (pMatrix) { | |
| 570 params.m_matrix.Concat(*pMatrix); | |
| 571 } | |
| 572 pTheme->DrawBackground(¶ms); | |
| 573 } | |
| 574 void CFWL_MonthCalendarImp::DrawTodayCircle(CFX_Graphics* pGraphics, | |
| 575 IFWL_ThemeProvider* pTheme, | |
| 576 const CFX_Matrix* pMatrix) { | |
| 577 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) { | |
| 578 return; | |
| 579 } | |
| 580 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) { | |
| 581 return; | |
| 582 } | |
| 583 CFWL_ThemeBackground params; | |
| 584 params.m_pWidget = m_pInterface; | |
| 585 params.m_iPart = CFWL_Part::TodayCircle; | |
| 586 params.m_pGraphics = pGraphics; | |
| 587 params.m_dwStates = CFWL_PartState_Normal; | |
| 588 params.m_rtPart = m_rtTodayFlag; | |
| 589 if (pMatrix) { | |
| 590 params.m_matrix.Concat(*pMatrix); | |
| 591 } | |
| 592 pTheme->DrawBackground(¶ms); | |
| 593 } | |
| 594 CFX_SizeF CFWL_MonthCalendarImp::CalcSize(FX_BOOL bAutoSize) { | |
| 595 if (!m_pProperties->m_pThemeProvider) | |
| 596 return CFX_SizeF(); | |
| 597 | |
| 598 if (!bAutoSize) { | |
| 599 GetClientRect(m_rtClient); | |
| 600 return CFX_SizeF(m_rtClient.width, m_rtClient.height); | |
| 601 } | |
| 602 | |
| 603 CFX_SizeF fs; | |
| 604 CFWL_ThemePart params; | |
| 605 params.m_pWidget = m_pInterface; | |
| 606 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 607 FX_FLOAT fMaxWeekW = 0.0f; | |
| 608 FX_FLOAT fMaxWeekH = 0.0f; | |
| 609 | |
| 610 for (uint32_t i = 0; i < 7; ++i) { | |
| 611 CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), | |
| 612 m_pProperties->m_pThemeProvider); | |
| 613 fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; | |
| 614 fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; | |
| 615 } | |
| 616 | |
| 617 FX_FLOAT fDayMaxW = 0.0f; | |
| 618 FX_FLOAT fDayMaxH = 0.0f; | |
| 619 for (int day = 10; day <= 31; day++) { | |
| 620 CFX_WideString wsDay; | |
| 621 wsDay.Format(L"%d", day); | |
| 622 CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider); | |
| 623 fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; | |
| 624 fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; | |
| 625 } | |
| 626 m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) | |
| 627 : (int)(fDayMaxW + 0.5)); | |
| 628 m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; | |
| 629 fs.x = m_szCell.x * MONTHCAL_COLUMNS + | |
| 630 MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + | |
| 631 MONTHCAL_HEADER_BTN_HMARGIN * 2; | |
| 632 FX_FLOAT fMonthMaxW = 0.0f; | |
| 633 FX_FLOAT fMonthMaxH = 0.0f; | |
| 634 | |
| 635 for (uint32_t i = 0; i < 12; ++i) { | |
| 636 CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), | |
| 637 m_pProperties->m_pThemeProvider); | |
| 638 fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; | |
| 639 fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; | |
| 640 } | |
| 641 CFX_WideString wsYear; | |
| 642 GetHeadText(m_iYear, m_iMonth, wsYear); | |
| 643 CFX_SizeF szYear = CalcTextSize(wsYear, m_pProperties->m_pThemeProvider); | |
| 644 fMonthMaxH = std::max(fMonthMaxH, szYear.y); | |
| 645 m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); | |
| 646 fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; | |
| 647 fs.x = std::max(fs.x, fMonthMaxW); | |
| 648 CFX_WideString wsToday; | |
| 649 GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); | |
| 650 CFX_WideString* wsText = static_cast<CFX_WideString*>( | |
| 651 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); | |
| 652 m_wsToday = *wsText + wsToday; | |
| 653 m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider); | |
| 654 m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; | |
| 655 fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + | |
| 656 MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; | |
| 657 return fs; | |
| 658 } | |
| 659 | |
| 660 void CFWL_MonthCalendarImp::CalcHeadSize() { | |
| 661 FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; | |
| 662 FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; | |
| 663 m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, | |
| 664 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + | |
| 665 MONTHCAL_VMARGIN + fHeadVMargin, | |
| 666 m_szHead.x, m_szHead.y); | |
| 667 } | |
| 668 void CFWL_MonthCalendarImp::CalcTodaySize() { | |
| 669 m_rtTodayFlag.Set( | |
| 670 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, | |
| 671 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, | |
| 672 m_szCell.x, m_szToday.y); | |
| 673 m_rtToday.Set( | |
| 674 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + | |
| 675 MONTHCAL_HMARGIN * 2, | |
| 676 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, | |
| 677 m_szToday.x, m_szToday.y); | |
| 678 } | |
| 679 void CFWL_MonthCalendarImp::LayOut() { | |
| 680 GetClientRect(m_rtClient); | |
| 681 { | |
| 682 m_rtHead.Set( | |
| 683 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, | |
| 684 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
| 685 m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); | |
| 686 m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, | |
| 687 m_rtHead.bottom(), | |
| 688 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
| 689 m_szCell.y + MONTHCAL_VMARGIN * 2); | |
| 690 m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, | |
| 691 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, | |
| 692 m_szCell.x); | |
| 693 m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - | |
| 694 MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, | |
| 695 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, | |
| 696 m_szCell.x); | |
| 697 m_rtHSep.Set( | |
| 698 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, | |
| 699 m_rtWeek.bottom() - MONTHCAL_VMARGIN, | |
| 700 m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, | |
| 701 MONTHCAL_HSEP_HEIGHT); | |
| 702 m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, | |
| 703 m_rtWeek.bottom(), | |
| 704 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
| 705 m_szCell.y * (MONTHCAL_ROWS - 3) + | |
| 706 MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); | |
| 707 } | |
| 708 CalDateItem(); | |
| 709 } | |
| 710 void CFWL_MonthCalendarImp::CalDateItem() { | |
| 711 FX_BOOL bNewWeek = FALSE; | |
| 712 int32_t iWeekOfMonth = 0; | |
| 713 FX_FLOAT fLeft = m_rtDates.left; | |
| 714 FX_FLOAT fTop = m_rtDates.top; | |
| 715 int32_t iCount = m_arrDates.GetSize(); | |
| 716 for (int32_t i = 0; i < iCount; i++) { | |
| 717 FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(i); | |
| 718 if (bNewWeek) { | |
| 719 iWeekOfMonth++; | |
| 720 bNewWeek = FALSE; | |
| 721 } | |
| 722 pDateInfo->rect.Set( | |
| 723 fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), | |
| 724 fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), | |
| 725 m_szCell.x + (MONTHCAL_HMARGIN * 2), | |
| 726 m_szCell.y + (MONTHCAL_VMARGIN * 2)); | |
| 727 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { | |
| 728 pDateInfo->rect.Offset(m_fWeekNumWid, 0); | |
| 729 } | |
| 730 if (pDateInfo->iDayOfWeek >= 6) { | |
| 731 bNewWeek = TRUE; | |
| 732 } | |
| 733 } | |
| 734 } | |
| 735 void CFWL_MonthCalendarImp::GetCapValue() { | |
| 736 if (!m_pProperties->m_pThemeProvider) { | |
| 737 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 738 } | |
| 739 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 740 CFWL_ThemePart part; | |
| 741 part.m_pWidget = m_pInterface; | |
| 742 m_fHeadWid = *static_cast<FX_FLOAT*>( | |
| 743 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); | |
| 744 m_fHeadHei = *static_cast<FX_FLOAT*>( | |
| 745 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); | |
| 746 m_fHeadBtnWid = *static_cast<FX_FLOAT*>( | |
| 747 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); | |
| 748 m_fHeadBtnHei = *static_cast<FX_FLOAT*>( | |
| 749 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); | |
| 750 m_fHeadBtnHMargin = *static_cast<FX_FLOAT*>( | |
| 751 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); | |
| 752 m_fHeadBtnVMargin = *static_cast<FX_FLOAT*>( | |
| 753 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); | |
| 754 m_fHeadTextWid = *static_cast<FX_FLOAT*>( | |
| 755 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); | |
| 756 m_fHeadTextHei = *static_cast<FX_FLOAT*>( | |
| 757 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); | |
| 758 m_fHeadTextHMargin = *static_cast<FX_FLOAT*>( | |
| 759 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); | |
| 760 m_fHeadTextVMargin = *static_cast<FX_FLOAT*>( | |
| 761 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); | |
| 762 m_fHSepWid = *static_cast<FX_FLOAT*>( | |
| 763 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); | |
| 764 m_fHSepHei = *static_cast<FX_FLOAT*>( | |
| 765 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); | |
| 766 m_fWeekNumWid = *static_cast<FX_FLOAT*>( | |
| 767 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); | |
| 768 m_fSepDOffset = *static_cast<FX_FLOAT*>( | |
| 769 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); | |
| 770 m_fSepX = *static_cast<FX_FLOAT*>( | |
| 771 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); | |
| 772 m_fSepY = *static_cast<FX_FLOAT*>( | |
| 773 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); | |
| 774 m_fWeekNumHeigh = *static_cast<FX_FLOAT*>( | |
| 775 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); | |
| 776 m_fWeekWid = *static_cast<FX_FLOAT*>( | |
| 777 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); | |
| 778 m_fWeekHei = *static_cast<FX_FLOAT*>( | |
| 779 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); | |
| 780 m_fDateCellWid = *static_cast<FX_FLOAT*>( | |
| 781 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); | |
| 782 m_fDateCellHei = *static_cast<FX_FLOAT*>( | |
| 783 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); | |
| 784 m_fTodayWid = *static_cast<FX_FLOAT*>( | |
| 785 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); | |
| 786 m_fTodayHei = *static_cast<FX_FLOAT*>( | |
| 787 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); | |
| 788 m_fTodayFlagWid = *static_cast<FX_FLOAT*>( | |
| 789 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); | |
| 790 m_fMCWid = *static_cast<FX_FLOAT*>( | |
| 791 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); | |
| 792 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { | |
| 793 m_fMCWid += m_fWeekNumWid; | |
| 794 } | |
| 795 m_fMCHei = *static_cast<FX_FLOAT*>( | |
| 796 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); | |
| 797 } | |
| 798 int32_t CFWL_MonthCalendarImp::CalWeekNumber(int32_t iYear, | |
| 799 int32_t iMonth, | |
| 800 int32_t iDay) { | |
| 801 return 0; | |
| 802 } | |
| 803 FX_BOOL CFWL_MonthCalendarImp::GetMinDate(int32_t& iYear, | |
| 804 int32_t& iMonth, | |
| 805 int32_t& iDay) { | |
| 806 iYear = m_dtMin.iYear; | |
| 807 iMonth = m_dtMin.iMonth; | |
| 808 iDay = m_dtMin.iDay; | |
| 809 return TRUE; | |
| 810 } | |
| 811 FX_BOOL CFWL_MonthCalendarImp::SetMinDate(int32_t iYear, | |
| 812 int32_t iMonth, | |
| 813 int32_t iDay) { | |
| 814 m_dtMin = DATE(iYear, iMonth, iDay); | |
| 815 return TRUE; | |
| 816 } | |
| 817 FX_BOOL CFWL_MonthCalendarImp::GetMaxDate(int32_t& iYear, | |
| 818 int32_t& iMonth, | |
| 819 int32_t& iDay) { | |
| 820 iYear = m_dtMax.iYear; | |
| 821 iMonth = m_dtMax.iMonth; | |
| 822 iDay = m_dtMax.iDay; | |
| 823 return TRUE; | |
| 824 } | |
| 825 FX_BOOL CFWL_MonthCalendarImp::SetMaxDate(int32_t iYear, | |
| 826 int32_t iMonth, | |
| 827 int32_t iDay) { | |
| 828 m_dtMax = DATE(iYear, iMonth, iDay); | |
| 829 return TRUE; | |
| 830 } | |
| 831 FX_BOOL CFWL_MonthCalendarImp::InitDate() { | |
| 832 if (m_pProperties->m_pDataProvider) { | |
| 833 IFWL_MonthCalendarDP* pDateProv = | |
| 834 static_cast<IFWL_MonthCalendarDP*>(m_pProperties->m_pDataProvider); | |
| 835 m_iYear = pDateProv->GetCurYear(m_pInterface); | |
| 836 m_iMonth = pDateProv->GetCurMonth(m_pInterface); | |
| 837 m_iDay = pDateProv->GetCurDay(m_pInterface); | |
| 838 m_iCurYear = m_iYear; | |
| 839 m_iCurMonth = m_iMonth; | |
| 840 } else { | |
| 841 m_iDay = 1; | |
| 842 m_iMonth = 1; | |
| 843 m_iYear = 1; | |
| 844 m_iCurYear = m_iYear; | |
| 845 m_iCurMonth = m_iMonth; | |
| 846 } | |
| 847 GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); | |
| 848 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); | |
| 849 m_dtMin = DATE(1500, 12, 1); | |
| 850 m_dtMax = DATE(2200, 1, 1); | |
| 851 return TRUE; | |
| 852 } | |
| 853 | |
| 854 void CFWL_MonthCalendarImp::ClearDateItem() { | |
| 855 for (int32_t i = 0; i < m_arrDates.GetSize(); i++) | |
| 856 delete m_arrDates.GetAt(i); | |
| 857 | |
| 858 m_arrDates.RemoveAll(); | |
| 859 } | |
| 860 | |
| 861 void CFWL_MonthCalendarImp::ReSetDateItem() { | |
| 862 m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); | |
| 863 int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); | |
| 864 int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); | |
| 865 for (int32_t i = 0; i < iDays; i++) { | |
| 866 if (iDayOfWeek >= 7) { | |
| 867 iDayOfWeek = 0; | |
| 868 } | |
| 869 CFX_WideString wsDay; | |
| 870 wsDay.Format(L"%d", i + 1); | |
| 871 uint32_t dwStates = 0; | |
| 872 if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) { | |
| 873 dwStates |= FWL_ITEMSTATE_MCD_Flag; | |
| 874 } | |
| 875 if (m_arrSelDays.Find(i + 1) != -1) { | |
| 876 dwStates |= FWL_ITEMSTATE_MCD_Selected; | |
| 877 } | |
| 878 CFX_RectF rtDate; | |
| 879 rtDate.Set(0, 0, 0, 0); | |
| 880 m_arrDates.Add( | |
| 881 new FWL_DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); | |
| 882 iDayOfWeek++; | |
| 883 } | |
| 884 } | |
| 885 FX_BOOL CFWL_MonthCalendarImp::NextMonth() { | |
| 886 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; | |
| 887 if (iMonth >= 12) { | |
| 888 iMonth = 1; | |
| 889 iYear++; | |
| 890 } else { | |
| 891 iMonth++; | |
| 892 } | |
| 893 DATE dt(m_iCurYear, m_iCurMonth, 1); | |
| 894 if (!(dt < m_dtMax)) { | |
| 895 return FALSE; | |
| 896 } | |
| 897 m_iCurYear = iYear, m_iCurMonth = iMonth; | |
| 898 ChangeToMonth(m_iCurYear, m_iCurMonth); | |
| 899 return TRUE; | |
| 900 } | |
| 901 FX_BOOL CFWL_MonthCalendarImp::PrevMonth() { | |
| 902 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; | |
| 903 if (iMonth <= 1) { | |
| 904 iMonth = 12; | |
| 905 iYear--; | |
| 906 } else { | |
| 907 iMonth--; | |
| 908 } | |
| 909 DATE dt(m_iCurYear, m_iCurMonth, 1); | |
| 910 if (!(dt > m_dtMin)) { | |
| 911 return FALSE; | |
| 912 } | |
| 913 m_iCurYear = iYear, m_iCurMonth = iMonth; | |
| 914 ChangeToMonth(m_iCurYear, m_iCurMonth); | |
| 915 return TRUE; | |
| 916 } | |
| 917 void CFWL_MonthCalendarImp::ChangeToMonth(int32_t iYear, int32_t iMonth) { | |
| 918 m_iCurYear = iYear; | |
| 919 m_iCurMonth = iMonth; | |
| 920 m_iHovered = -1; | |
| 921 ClearDateItem(); | |
| 922 ReSetDateItem(); | |
| 923 CalDateItem(); | |
| 924 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); | |
| 925 } | |
| 926 FX_BOOL CFWL_MonthCalendarImp::RemoveSelDay(int32_t iDay, FX_BOOL bAll) { | |
| 927 if (iDay == -1 && !bAll) { | |
| 928 return FALSE; | |
| 929 } | |
| 930 if (bAll) { | |
| 931 int32_t iCount = m_arrSelDays.GetSize(); | |
| 932 int32_t iDatesCount = m_arrDates.GetSize(); | |
| 933 for (int32_t i = 0; i < iCount; i++) { | |
| 934 int32_t iSelDay = m_arrSelDays.GetAt(i); | |
| 935 if (iSelDay <= iDatesCount) { | |
| 936 FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); | |
| 937 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; | |
| 938 } | |
| 939 } | |
| 940 m_arrSelDays.RemoveAll(); | |
| 941 } else { | |
| 942 int32_t index = m_arrSelDays.Find(iDay); | |
| 943 if (index == -1) { | |
| 944 return FALSE; | |
| 945 } | |
| 946 int32_t iSelDay = m_arrSelDays.GetAt(iDay); | |
| 947 int32_t iDatesCount = m_arrDates.GetSize(); | |
| 948 if (iSelDay <= iDatesCount) { | |
| 949 FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); | |
| 950 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; | |
| 951 } | |
| 952 m_arrSelDays.RemoveAt(index); | |
| 953 } | |
| 954 return TRUE; | |
| 955 } | |
| 956 FX_BOOL CFWL_MonthCalendarImp::AddSelDay(int32_t iDay) { | |
| 957 ASSERT(iDay > 0); | |
| 958 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) { | |
| 959 } else { | |
| 960 if (m_arrSelDays.Find(iDay) == -1) { | |
| 961 RemoveSelDay(-1, TRUE); | |
| 962 if (iDay <= m_arrDates.GetSize()) { | |
| 963 FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); | |
| 964 pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; | |
| 965 } | |
| 966 m_arrSelDays.Add(iDay); | |
| 967 } | |
| 968 } | |
| 969 return TRUE; | |
| 970 } | |
| 971 FX_BOOL CFWL_MonthCalendarImp::JumpToToday() { | |
| 972 if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { | |
| 973 m_iCurYear = m_iYear; | |
| 974 m_iCurMonth = m_iMonth; | |
| 975 ChangeToMonth(m_iYear, m_iMonth); | |
| 976 AddSelDay(m_iDay); | |
| 977 } else { | |
| 978 if (m_arrSelDays.Find(m_iDay) == -1) { | |
| 979 AddSelDay(m_iDay); | |
| 980 } | |
| 981 } | |
| 982 return TRUE; | |
| 983 } | |
| 984 void CFWL_MonthCalendarImp::GetHeadText(int32_t iYear, | |
| 985 int32_t iMonth, | |
| 986 CFX_WideString& wsHead) { | |
| 987 ASSERT(iMonth > 0 && iMonth < 13); | |
| 988 static const FX_WCHAR* const pMonth[] = { | |
| 989 L"January", L"February", L"March", L"April", | |
| 990 L"May", L"June", L"July", L"August", | |
| 991 L"September", L"October", L"November", L"December"}; | |
| 992 wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); | |
| 993 } | |
| 994 void CFWL_MonthCalendarImp::GetTodayText(int32_t iYear, | |
| 995 int32_t iMonth, | |
| 996 int32_t iDay, | |
| 997 CFX_WideString& wsToday) { | |
| 998 wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); | |
| 999 } | |
| 1000 int32_t CFWL_MonthCalendarImp::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { | |
| 1001 int32_t iCount = m_arrDates.GetSize(); | |
| 1002 for (int32_t i = 0; i < iCount; i++) { | |
| 1003 FWL_DATEINFO* pDateInfo = m_arrDates.GetAt(i); | |
| 1004 if (pDateInfo->rect.Contains(x, y)) { | |
| 1005 return ++i; | |
| 1006 } | |
| 1007 } | |
| 1008 return -1; | |
| 1009 } | |
| 1010 FX_BOOL CFWL_MonthCalendarImp::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { | |
| 1011 if (iDay <= 0 || iDay > m_arrDates.GetSize()) { | |
| 1012 return FALSE; | |
| 1013 } | |
| 1014 FWL_DATEINFO* pDateInfo = m_arrDates[iDay - 1]; | |
| 1015 if (!pDateInfo) | |
| 1016 return FALSE; | |
| 1017 rtDay = pDateInfo->rect; | |
| 1018 return TRUE; | |
| 1019 } | |
| 1020 | |
| 1021 CFWL_MonthCalendarImpDelegate::CFWL_MonthCalendarImpDelegate( | |
| 1022 CFWL_MonthCalendarImp* pOwner) | |
| 1023 : m_pOwner(pOwner) {} | |
| 1024 | |
| 1025 void CFWL_MonthCalendarImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 1026 if (!pMessage) | |
| 1027 return; | |
| 1028 | |
| 1029 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | |
| 1030 switch (dwMsgCode) { | |
| 1031 case CFWL_MessageType::SetFocus: { | |
| 1032 OnFocusChanged(pMessage, TRUE); | |
| 1033 break; | |
| 1034 } | |
| 1035 case CFWL_MessageType::KillFocus: { | |
| 1036 OnFocusChanged(pMessage, FALSE); | |
| 1037 break; | |
| 1038 } | |
| 1039 case CFWL_MessageType::Key: { | |
| 1040 break; | |
| 1041 } | |
| 1042 case CFWL_MessageType::Mouse: { | |
| 1043 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 1044 switch (pMouse->m_dwCmd) { | |
| 1045 case FWL_MouseCommand::LeftButtonDown: { | |
| 1046 OnLButtonDown(pMouse); | |
| 1047 break; | |
| 1048 } | |
| 1049 case FWL_MouseCommand::LeftButtonUp: { | |
| 1050 OnLButtonUp(pMouse); | |
| 1051 break; | |
| 1052 } | |
| 1053 case FWL_MouseCommand::Move: { | |
| 1054 OnMouseMove(pMouse); | |
| 1055 break; | |
| 1056 } | |
| 1057 case FWL_MouseCommand::Leave: { | |
| 1058 OnMouseLeave(pMouse); | |
| 1059 break; | |
| 1060 } | |
| 1061 default: | |
| 1062 break; | |
| 1063 } | |
| 1064 break; | |
| 1065 } | |
| 1066 default: { | |
| 1067 break; | |
| 1068 } | |
| 1069 } | |
| 1070 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 1071 } | |
| 1072 | |
| 1073 void CFWL_MonthCalendarImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1074 const CFX_Matrix* pMatrix) { | |
| 1075 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 1076 } | |
| 1077 | |
| 1078 void CFWL_MonthCalendarImpDelegate::OnActivate(CFWL_Message* pMsg) {} | |
| 1079 | |
| 1080 void CFWL_MonthCalendarImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | |
| 1081 FX_BOOL bSet) { | |
| 1082 if (bSet) { | |
| 1083 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 1084 } else { | |
| 1085 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 1086 } | |
| 1087 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1088 } | |
| 1089 void CFWL_MonthCalendarImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 1090 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1091 m_pOwner->m_iLBtnPartStates = CFWL_PartState_Pressed; | |
| 1092 m_pOwner->PrevMonth(); | |
| 1093 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1094 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1095 m_pOwner->m_iRBtnPartStates |= CFWL_PartState_Pressed; | |
| 1096 m_pOwner->NextMonth(); | |
| 1097 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1098 } else if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1099 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == | |
| 1100 0) { | |
| 1101 m_pOwner->JumpToToday(); | |
| 1102 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1103 } | |
| 1104 } else { | |
| 1105 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) { | |
| 1106 } else { | |
| 1107 int32_t iOldSel = 0; | |
| 1108 if (m_pOwner->m_arrSelDays.GetSize() > 0) { | |
| 1109 iOldSel = m_pOwner->m_arrSelDays[0]; | |
| 1110 } else { | |
| 1111 return; | |
| 1112 } | |
| 1113 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 1114 FX_BOOL bSelChanged = iCurSel > 0 && iCurSel != iOldSel; | |
| 1115 if (bSelChanged) { | |
| 1116 FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); | |
| 1117 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
| 1118 if (iOldSel > 0) { | |
| 1119 lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); | |
| 1120 rtInvalidate.Union(lpDatesInfo->rect); | |
| 1121 } | |
| 1122 m_pOwner->AddSelDay(iCurSel); | |
| 1123 CFWL_EvtClick wmClick; | |
| 1124 wmClick.m_pSrcTarget = m_pOwner->m_pInterface; | |
| 1125 m_pOwner->DispatchEvent(&wmClick); | |
| 1126 CFWL_EventMcdDateChanged wmDateSelected; | |
| 1127 wmDateSelected.m_iStartDay = iCurSel; | |
| 1128 wmDateSelected.m_iEndDay = iCurSel; | |
| 1129 wmDateSelected.m_iOldMonth = m_pOwner->m_iCurMonth; | |
| 1130 wmDateSelected.m_iOldYear = m_pOwner->m_iCurYear; | |
| 1131 wmDateSelected.m_pSrcTarget = m_pOwner->m_pInterface; | |
| 1132 m_pOwner->DispatchEvent(&wmDateSelected); | |
| 1133 m_pOwner->Repaint(&rtInvalidate); | |
| 1134 } | |
| 1135 } | |
| 1136 } | |
| 1137 } | |
| 1138 void CFWL_MonthCalendarImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 1139 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1140 m_pOwner->m_iLBtnPartStates = 0; | |
| 1141 m_pOwner->Repaint(&m_pOwner->m_rtLBtn); | |
| 1142 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1143 m_pOwner->m_iRBtnPartStates = 0; | |
| 1144 m_pOwner->Repaint(&m_pOwner->m_rtRBtn); | |
| 1145 } else if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1146 int32_t iDay = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 1147 if (iDay != -1) { | |
| 1148 m_pOwner->AddSelDay(iDay); | |
| 1149 } | |
| 1150 } | |
| 1151 } | |
| 1152 void CFWL_MonthCalendarImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
| 1153 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) { | |
| 1154 return; | |
| 1155 } | |
| 1156 FX_BOOL bRepaint = FALSE; | |
| 1157 CFX_RectF rtInvalidate; | |
| 1158 rtInvalidate.Set(0, 0, 0, 0); | |
| 1159 if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1160 int32_t iHover = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 1161 bRepaint = m_pOwner->m_iHovered != iHover; | |
| 1162 if (bRepaint) { | |
| 1163 if (m_pOwner->m_iHovered > 0) { | |
| 1164 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); | |
| 1165 } | |
| 1166 if (iHover > 0) { | |
| 1167 CFX_RectF rtDay; | |
| 1168 m_pOwner->GetDayRect(iHover, rtDay); | |
| 1169 if (rtInvalidate.IsEmpty()) { | |
| 1170 rtInvalidate = rtDay; | |
| 1171 } else { | |
| 1172 rtInvalidate.Union(rtDay); | |
| 1173 } | |
| 1174 } | |
| 1175 } | |
| 1176 m_pOwner->m_iHovered = iHover; | |
| 1177 } else { | |
| 1178 bRepaint = m_pOwner->m_iHovered > 0; | |
| 1179 if (bRepaint) { | |
| 1180 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); | |
| 1181 } | |
| 1182 m_pOwner->m_iHovered = -1; | |
| 1183 } | |
| 1184 if (bRepaint && !rtInvalidate.IsEmpty()) { | |
| 1185 m_pOwner->Repaint(&rtInvalidate); | |
| 1186 } | |
| 1187 } | |
| 1188 void CFWL_MonthCalendarImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
| 1189 if (m_pOwner->m_iHovered > 0) { | |
| 1190 CFX_RectF rtInvalidate; | |
| 1191 rtInvalidate.Set(0, 0, 0, 0); | |
| 1192 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); | |
| 1193 m_pOwner->m_iHovered = -1; | |
| 1194 if (!rtInvalidate.IsEmpty()) { | |
| 1195 m_pOwner->Repaint(&rtInvalidate); | |
| 1196 } | |
| 1197 } | |
| 1198 } | |
| 1199 | |
| 1200 FWL_DATEINFO::FWL_DATEINFO(int32_t day, | |
| 1201 int32_t dayofweek, | |
| 1202 uint32_t dwSt, | |
| 1203 CFX_RectF rc, | |
| 1204 CFX_WideString& wsday) | |
| 1205 : iDay(day), | |
| 1206 iDayOfWeek(dayofweek), | |
| 1207 dwStates(dwSt), | |
| 1208 rect(rc), | |
| 1209 wsDay(wsday) {} | |
| 1210 | |
| 1211 FWL_DATEINFO::~FWL_DATEINFO() {} | |
| OLD | NEW |