1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H 18 19 #include <optional> 20 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/picker/picker_data.h" 23 #include "core/components/theme/app_theme.h" 24 #include "core/components/picker/picker_theme.h" 25 #include "core/components_ng/base/frame_node.h" 26 #include "core/components_ng/event/event_hub.h" 27 #include "core/components_ng/pattern/button/button_layout_property.h" 28 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 29 #include "core/components_ng/pattern/pattern.h" 30 #include "core/components_ng/pattern/picker/datepicker_accessibility_property.h" 31 #include "core/components_ng/pattern/picker/datepicker_column_pattern.h" 32 #include "core/components_ng/pattern/picker/datepicker_event_hub.h" 33 #include "core/components_ng/pattern/picker/datepicker_layout_property.h" 34 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h" 35 #include "core/components_ng/pattern/text/text_pattern.h" 36 #include "core/components_ng/pattern/picker/datepicker_dialog_view.h" 37 38 namespace OHOS::Ace::NG { 39 class InspectorFilter; 40 namespace { 41 const Dimension FOCUS_PAINT_WIDTH = 2.0_vp; 42 } 43 44 class DatePickerPattern : public LinearLayoutPattern { 45 DECLARE_ACE_TYPE(DatePickerPattern, LinearLayoutPattern); 46 47 public: DatePickerPattern()48 DatePickerPattern() : LinearLayoutPattern(false) {}; 49 50 ~DatePickerPattern() override = default; 51 IsAtomicNode()52 bool IsAtomicNode() const override 53 { 54 return true; 55 } 56 CreateEventHub()57 RefPtr<EventHub> CreateEventHub() override 58 { 59 return MakeRefPtr<DatePickerEventHub>(); 60 } 61 CreateLayoutAlgorithm()62 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 63 { 64 return MakeRefPtr<LinearLayoutAlgorithm>(); 65 } 66 CreateLayoutProperty()67 RefPtr<LayoutProperty> CreateLayoutProperty() override 68 { 69 return MakeRefPtr<DataPickerRowLayoutProperty>(); 70 } 71 CreateNodePaintMethod()72 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 73 { 74 auto paintMethod = MakeRefPtr<DatePickerPaintMethod>(WeakClaim(this)); 75 paintMethod->SetEnabled(enabled_); 76 paintMethod->SetBackgroundColor(backgroundColor_); 77 return paintMethod; 78 } 79 CreateAccessibilityProperty()80 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 81 { 82 return MakeRefPtr<DatePickerAccessibilityProperty>(); 83 } 84 SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)85 void SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode) 86 { 87 weakButtonConfirm_ = buttonConfirmNode; 88 } 89 SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)90 void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode) 91 { 92 weakButtonCancel_ = buttonCancelNode; 93 } 94 SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)95 void SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode) 96 { 97 weakLunarSwitchText_ = lunarSwitchTextNode; 98 } 99 100 void OnFontConfigurationUpdate() override; 101 102 void OnFontScaleConfigurationUpdate() override; 103 104 void OnLanguageConfigurationUpdate() override; 105 106 void OnColorConfigurationUpdate() override; 107 108 bool OnThemeScopeUpdate(int32_t themeScopeId) override; 109 110 void SetChangeCallback(ColumnChangeCallback&& value); 111 112 void HandleColumnChange(const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, bool needNotify); 113 114 void SolarColumnsBuilding(const PickerDate& current); 115 116 void LunarColumnsBuilding(const LunarDate& current); 117 118 void SolarMonthDaysColumnsBuilding(const PickerDate& current); 119 120 void LunarMonthDaysColumnBuilding(const LunarDate& current); 121 122 void HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 123 124 void HandleMonthChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 125 126 void HandleLunarMonthChange(bool isAdd, uint32_t index); 127 128 void HandleLunarYearChange(bool isAdd, uint32_t index); 129 130 void HandleSolarYearChange(bool isAdd, uint32_t index); 131 132 LunarDate GetCurrentLunarDate(uint32_t lunarYear) const; 133 134 void OrderCurrentLunarDate( 135 RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const; 136 137 void HandleSolarMonthChange(bool isAdd, uint32_t index); 138 139 void HandleDayChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 140 141 void HandleReduceLunarDayChange(uint32_t index); 142 143 void HandleLunarDayChange(bool isAdd, uint32_t index); 144 145 void HandleAddLunarDayChange(uint32_t index); 146 147 void HandleSolarDayChange(bool isAdd, uint32_t index); 148 149 void IncreaseLinkageYearMonth(PickerDate& date); 150 151 void ReduceLinkageYearMonth(PickerDate& date); 152 153 void HandleSolarMonthDaysChange(bool isAdd, uint32_t index); 154 155 void HandleLunarMonthDaysChange(bool isAdd, uint32_t index); 156 157 void HandleAddLunarMonthDaysChange(uint32_t index); 158 159 void HandleReduceLunarMonthDaysChange(uint32_t index); 160 161 LunarDate GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const; 162 163 PickerDate GetCurrentDate() const; 164 165 void SetEventCallback(EventCallback&& value); 166 167 void FireChangeEvent(bool refresh); 168 169 void FlushColumn(); 170 171 void FlushMonthDaysColumn(); 172 173 void AdjustLunarDate(LunarDate& date); 174 175 int LunarDateCompare(const LunarDate& left, const LunarDate& right) const; 176 177 std::unordered_map<std::string, RefPtr<FrameNode>> GetAllChildNode(); 178 179 void OrderAllChildNode(RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay); 180 GetColumn(const int32_t & tag)181 RefPtr<FrameNode> GetColumn(const int32_t& tag) const 182 { 183 auto iter = std::find_if(datePickerColumns_.begin(), datePickerColumns_.end(), [&tag](const auto& c) { 184 auto column = c.Upgrade(); 185 return column && column->GetId() == tag; 186 }); 187 return (iter == datePickerColumns_.end()) ? nullptr : (*iter).Upgrade(); 188 } 189 SetColumn(const RefPtr<FrameNode> & value)190 void SetColumn(const RefPtr<FrameNode>& value) 191 { 192 datePickerColumns_.emplace_back(value); 193 } 194 ClearColumn()195 void ClearColumn() 196 { 197 datePickerColumns_.clear(); 198 } 199 SetShowLunar(bool value)200 void SetShowLunar(bool value) 201 { 202 isForceUpdate_ = value != lunar_; 203 lunar_ = value; 204 } 205 IsShowLunar()206 bool IsShowLunar() const 207 { 208 return lunar_; 209 } 210 SetShowMonthDaysFlag(bool value)211 void SetShowMonthDaysFlag(bool value) 212 { 213 showMonthDays_ = value; 214 } 215 ShowMonthDays()216 bool ShowMonthDays() const 217 { 218 return showMonthDays_; 219 } 220 SetShowTimeFlag(bool value)221 void SetShowTimeFlag(bool value) 222 { 223 showTime_ = value; 224 } 225 SetShowLunarSwitch(bool value)226 void SetShowLunarSwitch(bool value) 227 { 228 showLunarSwitch_ = value; 229 } 230 GetShowLunarSwitch()231 bool GetShowLunarSwitch() 232 { 233 return showLunarSwitch_; 234 } 235 GetDialogAcceptEvent()236 const EventMarker& GetDialogAcceptEvent() const 237 { 238 return OnDialogAccept_; 239 } SetDialogAcceptEvent(const EventMarker & value)240 void SetDialogAcceptEvent(const EventMarker& value) 241 { 242 OnDialogAccept_ = value; 243 } 244 GetDialogCancelEvent()245 const EventMarker& GetDialogCancelEvent() const 246 { 247 return OnDialogCancel_; 248 } SetDialogCancelEvent(const EventMarker & value)249 void SetDialogCancelEvent(const EventMarker& value) 250 { 251 OnDialogCancel_ = value; 252 } 253 GetDialogChangeEvent()254 const EventMarker& GetDialogChangeEvent() const 255 { 256 return OnDialogChange_; 257 } SetDialogChangeEvent(const EventMarker & value)258 void SetDialogChangeEvent(const EventMarker& value) 259 { 260 OnDialogChange_ = value; 261 } 262 SetResizePickerItemHeight(double resizePickerItemHeight)263 void SetResizePickerItemHeight(double resizePickerItemHeight) 264 { 265 resizePickerItemHeight_ = resizePickerItemHeight; 266 } 267 GetResizePickerItemHeight()268 double GetResizePickerItemHeight() const 269 { 270 return resizePickerItemHeight_; 271 } 272 SetResizeFlag(bool resizeFlag)273 void SetResizeFlag(bool resizeFlag) 274 { 275 resizeFlag_ = resizeFlag; 276 } 277 GetResizeFlag()278 bool GetResizeFlag() const 279 { 280 return resizeFlag_; 281 } 282 SetIsShowInDialog(bool isShowInDialog)283 void SetIsShowInDialog(bool isShowInDialog) 284 { 285 isShowInDialog_ = isShowInDialog; 286 } 287 GetIsShowInDialog()288 bool GetIsShowInDialog() const 289 { 290 return isShowInDialog_; 291 } 292 GetOptionCount(RefPtr<FrameNode> & frameNode)293 uint32_t GetOptionCount(RefPtr<FrameNode>& frameNode) 294 { 295 return options_[frameNode].size(); 296 } 297 GetOptionValue(RefPtr<FrameNode> & frameNode,uint32_t index)298 PickerDateF GetOptionValue(RefPtr<FrameNode>& frameNode, uint32_t index) 299 { 300 if (index >= GetOptionCount(frameNode)) { 301 LOGE("index out of range."); 302 return {}; 303 } 304 return options_[frameNode][index]; 305 } 306 GetAllOptions(RefPtr<FrameNode> & frameNode)307 const std::vector<PickerDateF>& GetAllOptions(RefPtr<FrameNode>& frameNode) 308 { 309 return options_[frameNode]; 310 } 311 GetOptions()312 const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& GetOptions() const 313 { 314 return options_; 315 } 316 GetShowCount()317 uint32_t GetShowCount() const 318 { 319 return showCount_; 320 } 321 SetShowCount(uint32_t showCount)322 void SetShowCount(uint32_t showCount) 323 { 324 showCount_ = showCount; 325 } 326 SetDateOrder(std::string dateOrder)327 void SetDateOrder(std::string dateOrder) 328 { 329 isDateOrderChange_ = dateOrder != dateOrder_; 330 dateOrder_ = dateOrder; 331 } 332 GetYearFormatString(uint32_t year)333 static std::string GetYearFormatString(uint32_t year) 334 { 335 return PickerStringFormatter::GetYear(year); 336 } 337 GetMonthFormatString(uint32_t month,bool isLunar,bool isLeap)338 static std::string GetMonthFormatString(uint32_t month, bool isLunar, bool isLeap) 339 { 340 if (isLunar) { 341 return PickerStringFormatter::GetLunarMonth(month, isLeap); 342 } 343 return PickerStringFormatter::GetSolarMonth(month); 344 } 345 GetDayFormatString(uint32_t day,bool isLunar)346 static std::string GetDayFormatString(uint32_t day, bool isLunar) 347 { 348 if (isLunar) { 349 return PickerStringFormatter::GetLunarDay(day); 350 } 351 return PickerStringFormatter::GetSolarDay(day); 352 } 353 354 uint32_t GetLunarMaxDay(uint32_t year, uint32_t month, bool isLeap) const; 355 356 bool GetLunarLeapMonth(uint32_t year, uint32_t& outLeapMonth) const; 357 358 LunarDate SolarToLunar(const PickerDate& date) const; 359 360 PickerDate LunarToSolar(const LunarDate& date) const; 361 362 void UpdateCurrentOffset(float offset); 363 364 void OnDataLinking( 365 const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 366 367 void HandleMonthDaysChange( 368 const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 369 370 std::string GetSelectedObject(bool isColumnChange, int status = -1) const; 371 GetSelectDate()372 const LunarDate& GetSelectDate() 373 { 374 return selectedLunar_; 375 } 376 SetSelectDate(const PickerDate & value)377 void SetSelectDate(const PickerDate& value) 378 { 379 selectedDate_ = value; 380 isFiredDateChange_ = firedDateStr_.has_value() && firedDateStr_.value() == GetSelectedObject(false); 381 firedDateStr_.reset(); 382 if (selectedDate_.GetYear() <= 0) { 383 LOGW("selectedDate error"); 384 selectedDate_ = PickerDate::Current(); 385 } 386 AdjustSolarDate(selectedDate_, startDateSolar_, endDateSolar_); 387 selectedLunar_ = SolarToLunar(selectedDate_); 388 } 389 GetSelectedDate()390 const PickerDate& GetSelectedDate() 391 { 392 return selectedDate_; 393 } 394 SetStartDate(const PickerDate & value)395 void SetStartDate(const PickerDate& value) 396 { 397 startDateSolar_ = value; 398 AdjustSolarDate(startDateSolar_, limitStartDate_, limitEndDate_); 399 startDateLunar_ = SolarToLunar(startDateSolar_); 400 } 401 GetStartDateLunar()402 const LunarDate& GetStartDateLunar() 403 { 404 return startDateLunar_; 405 } 406 GetStartDateSolar()407 const PickerDate& GetStartDateSolar() 408 { 409 return startDateSolar_; 410 } 411 SetEndDate(const PickerDate & value)412 void SetEndDate(const PickerDate& value) 413 { 414 endDateSolar_ = value; 415 AdjustSolarDate(endDateSolar_, limitStartDate_, limitEndDate_); 416 endDateLunar_ = SolarToLunar(endDateSolar_); 417 } 418 GetEndDateLunar()419 const LunarDate& GetEndDateLunar() 420 { 421 return endDateLunar_; 422 } 423 GetEndDateSolar()424 const PickerDate& GetEndDateSolar() 425 { 426 return endDateSolar_; 427 } 428 SetMode(const DatePickerMode & value)429 void SetMode(const DatePickerMode& value) 430 { 431 datePickerMode_ = value; 432 } 433 GetMode()434 const DatePickerMode& GetMode() 435 { 436 return datePickerMode_; 437 } 438 AdjustSolarDate(PickerDate & date,const PickerDate & start,const PickerDate & end)439 void AdjustSolarDate(PickerDate& date, const PickerDate& start, const PickerDate& end) const 440 { 441 if (SolarDateCompare(date, start) < 0) { 442 date = start; 443 return; 444 } 445 if (SolarDateCompare(date, end) > 0) { 446 date = end; 447 } 448 } 449 AdjustSolarDate(PickerDate & date)450 void AdjustSolarDate(PickerDate& date) const 451 { 452 AdjustSolarDate(date, startDateSolar_, endDateSolar_); 453 } 454 SolarDateCompare(const PickerDate & left,const PickerDate & right)455 static int SolarDateCompare(const PickerDate& left, const PickerDate& right) 456 { 457 static const int leftEqualRight = 0; // means left = right 458 static const int leftGreatRight = 1; // means left > right 459 static const int leftLessRight = -1; // means left < right 460 if (left.GetYear() > right.GetYear()) { 461 return leftGreatRight; 462 } 463 if (left.GetYear() < right.GetYear()) { 464 return leftLessRight; 465 } 466 if (left.GetMonth() > right.GetMonth()) { 467 return leftGreatRight; 468 } 469 if (left.GetMonth() < right.GetMonth()) { 470 return leftLessRight; 471 } 472 if (left.GetDay() > right.GetDay()) { 473 return leftGreatRight; 474 } 475 if (left.GetDay() < right.GetDay()) { 476 return leftLessRight; 477 } 478 return leftEqualRight; 479 } 480 HasYearNode()481 bool HasYearNode() const 482 { 483 return yearId_.has_value(); 484 } 485 GetYearId()486 int32_t GetYearId() 487 { 488 if (!yearId_.has_value()) { 489 yearId_ = ElementRegister::GetInstance()->MakeUniqueId(); 490 } 491 return yearId_.value(); 492 } 493 HasMonthNode()494 bool HasMonthNode() const 495 { 496 return monthId_.has_value(); 497 } 498 GetMonthId()499 int32_t GetMonthId() 500 { 501 if (!monthId_.has_value()) { 502 monthId_ = ElementRegister::GetInstance()->MakeUniqueId(); 503 } 504 return monthId_.value(); 505 } 506 HasDayNode()507 bool HasDayNode() const 508 { 509 return dayId_.has_value(); 510 } 511 GetDayId()512 int32_t GetDayId() 513 { 514 if (!dayId_.has_value()) { 515 dayId_ = ElementRegister::GetInstance()->MakeUniqueId(); 516 } 517 return dayId_.value(); 518 } 519 HasMonthDaysNode()520 bool HasMonthDaysNode() const 521 { 522 return monthDaysId_.has_value(); 523 } 524 GetMonthDaysId()525 int32_t GetMonthDaysId() 526 { 527 if (!monthDaysId_.has_value()) { 528 monthDaysId_ = ElementRegister::GetInstance()->MakeUniqueId(); 529 } 530 return monthDaysId_.value(); 531 } 532 HasTitleNode()533 bool HasTitleNode() const 534 { 535 return titleId_.has_value(); 536 } 537 SetTitleId(const int32_t id)538 bool SetTitleId(const int32_t id) 539 { 540 if (HasTitleNode()) { 541 return false; 542 } 543 titleId_ = id; 544 return true; 545 } 546 GetTitleId()547 int32_t GetTitleId() 548 { 549 if (!titleId_.has_value()) { 550 titleId_ = ElementRegister::GetInstance()->MakeUniqueId(); 551 } 552 return titleId_.value(); 553 } 554 HasButtonTitleNode()555 bool HasButtonTitleNode() const 556 { 557 return ButtonTitleId_.has_value(); 558 } 559 GetButtonTitleId()560 int32_t GetButtonTitleId() 561 { 562 if (!ButtonTitleId_.has_value()) { 563 ButtonTitleId_ = ElementRegister::GetInstance()->MakeUniqueId(); 564 } 565 return ButtonTitleId_.value(); 566 } 567 HasDividerNode()568 bool HasDividerNode() const 569 { 570 return DividerId_.has_value(); 571 } 572 GetDividerId()573 int32_t GetDividerId() 574 { 575 if (!DividerId_.has_value()) { 576 DividerId_ = ElementRegister::GetInstance()->MakeUniqueId(); 577 } 578 return DividerId_.value(); 579 } 580 SetBackgroundColor(const Color & color)581 void SetBackgroundColor(const Color& color) 582 { 583 backgroundColor_ = color; 584 } 585 586 static const std::string& GetYear(uint32_t year); 587 588 static const std::string& GetSolarMonth(uint32_t month); 589 590 static const std::string& GetSolarDay(uint32_t day); 591 592 static const std::string& GetLunarMonth(uint32_t month, bool isLeap); 593 594 static const std::string& GetLunarDay(uint32_t day); 595 596 const std::string GetText(); 597 GetFocusPattern()598 FocusPattern GetFocusPattern() const override 599 { 600 auto pipeline = PipelineBase::GetCurrentContext(); 601 CHECK_NULL_RETURN(pipeline, FocusPattern()); 602 auto pickerTheme = pipeline->GetTheme<PickerTheme>(); 603 CHECK_NULL_RETURN(pickerTheme, FocusPattern()); 604 auto focusColor = pickerTheme->GetFocusColor(); 605 FocusPaintParam focusPaintParams; 606 focusPaintParams.SetPaintColor(focusColor); 607 return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams }; 608 } 609 SetCurrentFocusKeyID(int32_t value)610 void SetCurrentFocusKeyID(int32_t value) 611 { 612 focusKeyID_ = value; 613 } 614 GetCurrentFocusKeyID()615 int32_t GetCurrentFocusKeyID() 616 { 617 return focusKeyID_; 618 } 619 SetCurrentPage(uint32_t value)620 void SetCurrentPage(uint32_t value) 621 { 622 currentPage_ = value; 623 } 624 GetCurrentPage()625 uint32_t GetCurrentPage() 626 { 627 return currentPage_; 628 } 629 630 bool NeedAdaptForAging(); 631 632 void ShowTitle(int32_t titleId); 633 std::string GetVisibleColumnsText(); 634 void GetColumnText(const RefPtr<FrameNode>& columnNode, std::string& result); 635 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; SetContentRowNode(RefPtr<FrameNode> & contentRowNode)636 void SetContentRowNode(RefPtr<FrameNode>& contentRowNode) 637 { 638 contentRowNode_ = contentRowNode; 639 } SetbuttonTitleNode(RefPtr<FrameNode> & buttonTitleNode)640 void SetbuttonTitleNode(RefPtr<FrameNode>& buttonTitleNode) 641 { 642 buttonTitleNode_ = buttonTitleNode; 643 } 644 SetPickerTag(bool isPicker)645 void SetPickerTag(bool isPicker) 646 { 647 isPicker_ = isPicker; 648 } 649 650 void SetFocusDisable(); 651 void SetFocusEnable(); 652 static const std::string GetFormatString(PickerDateF data); 653 HasUserDefinedDisappearFontFamily(bool isUserDefined)654 void HasUserDefinedDisappearFontFamily(bool isUserDefined) 655 { 656 hasUserDefinedDisappearFontFamily_ = isUserDefined; 657 } 658 GetHasUserDefinedDisappearFontFamily()659 bool GetHasUserDefinedDisappearFontFamily() 660 { 661 return hasUserDefinedDisappearFontFamily_; 662 } 663 HasUserDefinedNormalFontFamily(bool isUserDefined)664 void HasUserDefinedNormalFontFamily(bool isUserDefined) 665 { 666 hasUserDefinedNormalFontFamily_ = isUserDefined; 667 } 668 GetHasUserDefinedNormalFontFamily()669 bool GetHasUserDefinedNormalFontFamily() 670 { 671 return hasUserDefinedNormalFontFamily_; 672 } 673 HasUserDefinedSelectedFontFamily(bool isUserDefined)674 void HasUserDefinedSelectedFontFamily(bool isUserDefined) 675 { 676 hasUserDefinedSelectedFontFamily_ = isUserDefined; 677 } 678 GetHasUserDefinedSelectedFontFamily()679 bool GetHasUserDefinedSelectedFontFamily() 680 { 681 return hasUserDefinedSelectedFontFamily_; 682 } 683 updateFontConfigurationEvent(const std::function<void ()> & closeDialogEvent)684 void updateFontConfigurationEvent(const std::function<void()>& closeDialogEvent) 685 { 686 closeDialogEvent_ = closeDialogEvent; 687 } 688 GetTextProperties()689 const PickerTextProperties& GetTextProperties() const 690 { 691 return textProperties_; 692 } 693 SetTextProperties(const PickerTextProperties & properties)694 void SetTextProperties(const PickerTextProperties& properties) 695 { 696 textProperties_ = properties; 697 if (properties.disappearTextStyle_.fontSize.has_value() && properties.disappearTextStyle_.fontSize->IsValid()) { 698 isUserSetGradientFont_ = true; 699 gradientHeight_ = properties.disappearTextStyle_.fontSize.value(); 700 } 701 702 if (properties.normalTextStyle_.fontSize.has_value() && properties.normalTextStyle_.fontSize->IsValid()) { 703 isUserSetGradientFont_ = true; 704 gradientHeight_ = std::max(properties.normalTextStyle_.fontSize.value(), gradientHeight_); 705 } 706 707 if (properties.selectedTextStyle_.fontSize.has_value() && properties.selectedTextStyle_.fontSize->IsValid()) { 708 isUserSetDividerSpacingFont_ = true; 709 dividerSpacing_ = properties.selectedTextStyle_.fontSize.value(); 710 } 711 } 712 GetIsUserSetDividerSpacingFont()713 bool GetIsUserSetDividerSpacingFont() 714 { 715 return isUserSetDividerSpacingFont_; 716 } 717 GetIsUserSetGradientFont()718 bool GetIsUserSetGradientFont() 719 { 720 return isUserSetGradientFont_; 721 } 722 GetDividerSpacing()723 Dimension GetDividerSpacing() 724 { 725 return dividerSpacing_; 726 } 727 GetGradientHeight()728 Dimension GetGradientHeight() 729 { 730 return gradientHeight_; 731 } 732 SetPaintDividerSpacing(float & value)733 void SetPaintDividerSpacing(float& value) 734 { 735 paintDividerSpacing_ = value; 736 } 737 GetPaintDividerSpacing()738 float GetPaintDividerSpacing() 739 { 740 return paintDividerSpacing_; 741 } 742 743 static bool ReportDateChangeEvent(int32_t nodeId, const std::string& compName, 744 const std::string& eventName, const std::string& eventData); 745 SetUserDefinedOpacity(double opacity)746 void SetUserDefinedOpacity(double opacity) 747 { 748 curOpacity_ = opacity; 749 } 750 SetEnableHapticFeedback(bool value)751 void SetEnableHapticFeedback(bool value) 752 { 753 if (isEnableHaptic_ != value) { 754 isHapticChanged_ = true; 755 } 756 isEnableHaptic_ = value; 757 } 758 GetEnableHapticFeedback()759 bool GetEnableHapticFeedback() const 760 { 761 return isEnableHaptic_; 762 } 763 764 void ColumnPatternInitHapticController(); 765 void ColumnPatternInitHapticController(const RefPtr<FrameNode>& columnNode); 766 void ColumnPatternStopHaptic(); 767 768 void SetDigitalCrownSensitivity(int32_t crownSensitivity); 769 void UpdateUserSetSelectColor(); 770 private: 771 void OnModifyDone() override; 772 void OnAttachToFrameNode() override; 773 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 774 static void Init(); 775 void InitDisabled(); 776 void GetInnerFocusPaintRect(RoundRect& paintRect); 777 void PaintFocusState(); 778 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 779 bool OnKeyEvent(const KeyEvent& event); 780 bool HandleDirectionKey(KeyCode code); 781 void InitFocusEvent(); 782 void InitSelectorProps(); 783 void HandleFocusEvent(); 784 void HandleBlurEvent(); 785 void AddIsFocusActiveUpdateEvent(); 786 void RemoveIsFocusActiveUpdateEvent(); 787 void GetInnerFocusButtonPaintRect(RoundRect& paintRect, float focusButtonXOffset); 788 void UpdateFocusButtonState(); 789 void SetHaveFocus(bool haveFocus); 790 void UpdateColumnButtonStyles(const RefPtr<FrameNode>& columnNode, bool haveFocus, bool needMarkDirty); 791 PickerDate GetCurrentDateByMonthDaysColumn() const; 792 PickerDate GetCurrentDateByYearMonthDayColumn() const; 793 void OrderCurrentDateByYearMonthDayColumn( 794 RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const; 795 void FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn); 796 void UpdateTitleTextColor(const RefPtr<FrameNode>& buttonTitleNode, const RefPtr<PickerTheme>& pickerTheme); 797 void FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn); 798 void AdjustSolarStartEndDate(); 799 void AdjustLunarStartEndDate(); 800 void UpdateButtonMargin( 801 const RefPtr<FrameNode>& buttonNode, const RefPtr<DialogTheme>& dialogTheme, const bool isConfirmNode); 802 void UpdateButtonNode(const RefPtr<FrameNode>& buttonNode, const bool isConfirmNode); 803 void ShowColumnByDatePickMode(); 804 void UpdateStackPropVisibility(const RefPtr<FrameNode>& stackNode, 805 const VisibleType visibleType, const int32_t weight); 806 void ClearFocus(); 807 void SetDefaultFocus(); 808 bool IsCircle(); 809 bool CurrentIsLunar(); 810 #ifdef SUPPORT_DIGITAL_CROWN 811 void InitOnCrownEvent(const RefPtr<FocusHub>& focusHub); 812 bool OnCrownEvent(const CrownEvent& event); 813 #endif 814 void InitFocusKeyEvent(); 815 void FlushChildNodes(); 816 void UpdateLunarSwitch(); 817 void UpdateDateOrder(); 818 819 RefPtr<ClickEvent> clickEventListener_; 820 bool enabled_ = true; 821 int32_t focusKeyID_ = 0; 822 uint32_t currentPage_ = 0; 823 std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>> options_; 824 uint32_t showCount_ = 0; 825 std::string dateOrder_ = ""; 826 std::vector<WeakPtr<FrameNode>> datePickerColumns_; 827 bool lunar_ = false; 828 bool showMonthDays_ = false; 829 bool showTime_ = false; 830 bool showLunarSwitch_ = false; 831 Color backgroundColor_ = Color::WHITE; 832 std::optional<int32_t> yearId_; 833 std::optional<int32_t> monthId_; 834 std::optional<int32_t> dayId_; 835 std::optional<int32_t> monthDaysId_; 836 std::optional<int32_t> dateNodeId_; 837 std::optional<int32_t> titleId_; 838 std::optional<int32_t> ButtonTitleId_; 839 std::optional<int32_t> DividerId_; 840 double resizePickerItemHeight_ = 0.0; 841 bool resizeFlag_ = false; 842 bool isShowInDialog_ = false; 843 bool focusEventInitialized_ = false; 844 bool haveFocus_ = false; 845 bool useButtonFocusArea_ = false; 846 Dimension selectorItemRadius_ = 8.0_vp; 847 std::function<void(bool)> isFocusActiveUpdateEvent_; 848 EventMarker OnDialogAccept_; 849 EventMarker OnDialogCancel_; 850 EventMarker OnDialogChange_; 851 WeakPtr<FrameNode> weakButtonConfirm_; 852 WeakPtr<FrameNode> weakButtonCancel_; 853 WeakPtr<FrameNode> weakLunarSwitchText_; 854 PickerDate startDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document. 855 LunarDate startDateLunar_; 856 PickerDate endDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document. 857 LunarDate endDateLunar_; 858 PickerDate selectedDate_ = PickerDate::Current(); 859 LunarDate selectedLunar_; 860 PickerDate startDefaultDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document. 861 PickerDate endDefaultDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document. 862 const PickerDate limitStartDate_ = PickerDate(1900, 1, 31); 863 const PickerDate limitEndDate_ = PickerDate(2100, 12, 31); 864 static bool inited_; 865 static const std::string empty_; 866 static const PickerDateF emptyPickerDate_; 867 static std::unordered_map<uint32_t, std::string> years_; // year from 1900 to 2100,count is 201 868 static std::unordered_map<uint32_t, std::string> solarMonths_; // solar month from 1 to 12,count is 12 869 static std::unordered_map<uint32_t, std::string> solarDays_; // solar day from 1 to 31, count is 31 870 static std::unordered_map<uint32_t, std::string> lunarMonths_; // lunar month from 1 to 24, count is 24 871 static std::unordered_map<uint32_t, std::string> lunarDays_; // lunar day from 1 to 30, count is 30 872 static std::vector<std::string> tagOrder_; // year month day tag order 873 static std::vector<std::string> localizedMonths_; 874 WeakPtr<FrameNode> contentRowNode_; 875 WeakPtr<FrameNode> buttonTitleNode_; 876 bool isPicker_ = false; 877 bool isFiredDateChange_ = false; 878 bool isForceUpdate_ = false; 879 bool isDateOrderChange_ = false; 880 std::optional<std::string> firedDateStr_; 881 void CalcLeftTotalColumnWidth(const RefPtr<FrameNode>& host, float &leftTotalColumnWidth, float childSize); 882 bool CheckFocusID(int32_t childSize); 883 bool ParseDirectionKey(RefPtr<DatePickerColumnPattern>& pattern, KeyCode& code, uint32_t totalOptionCount, 884 int32_t childSize); 885 bool ReportDateChangeEvent(const std::string& compName, 886 const std::string& eventName, const std::string& eventData); 887 888 bool hasUserDefinedDisappearFontFamily_ = false; 889 bool hasUserDefinedNormalFontFamily_ = false; 890 bool hasUserDefinedSelectedFontFamily_ = false; 891 std::function<void()> closeDialogEvent_; 892 bool isUserSetDividerSpacingFont_ = false; 893 bool isUserSetGradientFont_ = false; 894 Dimension gradientHeight_; 895 Dimension dividerSpacing_; 896 float paintDividerSpacing_ = 1.0f; 897 PickerTextProperties textProperties_; 898 double curOpacity_ = 1.0; 899 DatePickerMode datePickerMode_ = DatePickerMode::DATE; 900 bool isFocus_ = true; 901 bool isEnableHaptic_ = true; 902 bool isHapticChanged_ = true; 903 904 ACE_DISALLOW_COPY_AND_MOVE(DatePickerPattern); 905 std::string selectedColumnId_; 906 bool lastTimeIsLuanar_ = true; 907 bool isFirstTimeSetFocus_ = true; 908 }; 909 } // namespace OHOS::Ace::NG 910 911 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H 912