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/picker/picker_theme.h" 24 #include "core/components_ng/base/frame_node.h" 25 #include "core/components_ng/event/event_hub.h" 26 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 27 #include "core/components_ng/pattern/pattern.h" 28 #include "core/components_ng/pattern/picker/datepicker_accessibility_property.h" 29 #include "core/components_ng/pattern/picker/datepicker_column_pattern.h" 30 #include "core/components_ng/pattern/picker/datepicker_event_hub.h" 31 #include "core/components_ng/pattern/picker/datepicker_layout_property.h" 32 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h" 33 #include "core/components_ng/pattern/text/text_pattern.h" 34 #include "core/components_ng/pattern/picker/datepicker_dialog_view.h" 35 36 namespace OHOS::Ace::NG { 37 class InspectorFilter; 38 namespace { 39 const Dimension FOCUS_PAINT_WIDTH = 2.0_vp; 40 } 41 42 class DatePickerPattern : public LinearLayoutPattern { 43 DECLARE_ACE_TYPE(DatePickerPattern, LinearLayoutPattern); 44 45 public: DatePickerPattern()46 DatePickerPattern() : LinearLayoutPattern(false) {}; 47 48 ~DatePickerPattern() override = default; 49 IsAtomicNode()50 bool IsAtomicNode() const override 51 { 52 return true; 53 } 54 CreateEventHub()55 RefPtr<EventHub> CreateEventHub() override 56 { 57 return MakeRefPtr<DatePickerEventHub>(); 58 } 59 CreateLayoutAlgorithm()60 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 61 { 62 return MakeRefPtr<LinearLayoutAlgorithm>(); 63 } 64 CreateLayoutProperty()65 RefPtr<LayoutProperty> CreateLayoutProperty() override 66 { 67 return MakeRefPtr<DataPickerRowLayoutProperty>(); 68 } 69 CreateNodePaintMethod()70 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 71 { 72 auto paintMethod = MakeRefPtr<DatePickerPaintMethod>(WeakClaim(this)); 73 paintMethod->SetEnabled(enabled_); 74 paintMethod->SetBackgroundColor(backgroundColor_); 75 return paintMethod; 76 } 77 CreateAccessibilityProperty()78 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 79 { 80 return MakeRefPtr<DatePickerAccessibilityProperty>(); 81 } 82 SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)83 void SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode) 84 { 85 weakButtonConfirm_ = buttonConfirmNode; 86 } 87 SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)88 void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode) 89 { 90 weakButtonCancel_ = buttonCancelNode; 91 } 92 SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)93 void SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode) 94 { 95 weakLunarSwitchText_ = lunarSwitchTextNode; 96 } 97 OnFontConfigurationUpdate()98 void OnFontConfigurationUpdate() override 99 { 100 if (closeDialogEvent_) { 101 closeDialogEvent_(); 102 } 103 } 104 105 void OnLanguageConfigurationUpdate() override; 106 107 void OnColorConfigurationUpdate() override; 108 109 void SetChangeCallback(ColumnChangeCallback&& value); 110 111 void HandleColumnChange(const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, bool needNotify); 112 113 void SolarColumnsBuilding(const PickerDate& current); 114 115 void LunarColumnsBuilding(const LunarDate& current); 116 117 void SolarMonthDaysColumnsBuilding(const PickerDate& current); 118 119 void LunarMonthDaysColumnBuilding(const LunarDate& current); 120 121 void HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 122 123 void HandleMonthChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 124 125 void HandleLunarMonthChange(bool isAdd, uint32_t index); 126 127 void HandleLunarYearChange(bool isAdd, uint32_t index); 128 129 void HandleSolarYearChange(bool isAdd, uint32_t index); 130 131 LunarDate GetCurrentLunarDate(uint32_t lunarYear) const; 132 133 void OrderCurrentLunarDate( 134 RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const; 135 136 void HandleSolarMonthChange(bool isAdd, uint32_t index); 137 138 void HandleDayChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 139 140 void HandleReduceLunarDayChange(uint32_t index); 141 142 void HandleLunarDayChange(bool isAdd, uint32_t index); 143 144 void HandleAddLunarDayChange(uint32_t index); 145 146 void HandleSolarDayChange(bool isAdd, uint32_t index); 147 148 void HandleSolarMonthDaysChange(bool isAdd, uint32_t index); 149 150 void HandleLunarMonthDaysChange(bool isAdd, uint32_t index); 151 152 void HandleAddLunarMonthDaysChange(uint32_t index); 153 154 void HandleReduceLunarMonthDaysChange(uint32_t index); 155 156 LunarDate GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const; 157 158 PickerDate GetCurrentDate() const; 159 160 void SetEventCallback(EventCallback&& value); 161 162 void FireChangeEvent(bool refresh); 163 164 void FlushColumn(); 165 166 void FlushMonthDaysColumn(); 167 168 void AdjustLunarDate(LunarDate& date); 169 170 int LunarDateCompare(const LunarDate& left, const LunarDate& right) const; 171 172 std::unordered_map<std::string, RefPtr<FrameNode>> GetAllChildNode(); 173 174 void OrderAllChildNode(RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay); 175 GetColumn(const int32_t & tag)176 RefPtr<FrameNode> GetColumn(const int32_t& tag) const 177 { 178 auto iter = std::find_if(datePickerColumns_.begin(), datePickerColumns_.end(), [&tag](const auto& c) { 179 auto column = c.Upgrade(); 180 return column && column->GetId() == tag; 181 }); 182 return (iter == datePickerColumns_.end()) ? nullptr : (*iter).Upgrade(); 183 } 184 SetColumn(const RefPtr<FrameNode> & value)185 void SetColumn(const RefPtr<FrameNode>& value) 186 { 187 datePickerColumns_.emplace_back(value); 188 } 189 ClearColumn()190 void ClearColumn() 191 { 192 datePickerColumns_.clear(); 193 } 194 SetShowLunar(bool value)195 void SetShowLunar(bool value) 196 { 197 isForceUpdate_ = value != lunar_; 198 lunar_ = value; 199 } 200 IsShowLunar()201 bool IsShowLunar() const 202 { 203 return lunar_; 204 } 205 SetShowMonthDaysFlag(bool value)206 void SetShowMonthDaysFlag(bool value) 207 { 208 showMonthDays_ = value; 209 } 210 ShowMonthDays()211 bool ShowMonthDays() const 212 { 213 return showMonthDays_; 214 } 215 SetShowTimeFlag(bool value)216 void SetShowTimeFlag(bool value) 217 { 218 showTime_ = value; 219 } 220 GetDialogAcceptEvent()221 const EventMarker& GetDialogAcceptEvent() const 222 { 223 return OnDialogAccept_; 224 } SetDialogAcceptEvent(const EventMarker & value)225 void SetDialogAcceptEvent(const EventMarker& value) 226 { 227 OnDialogAccept_ = value; 228 } 229 GetDialogCancelEvent()230 const EventMarker& GetDialogCancelEvent() const 231 { 232 return OnDialogCancel_; 233 } SetDialogCancelEvent(const EventMarker & value)234 void SetDialogCancelEvent(const EventMarker& value) 235 { 236 OnDialogCancel_ = value; 237 } 238 GetDialogChangeEvent()239 const EventMarker& GetDialogChangeEvent() const 240 { 241 return OnDialogChange_; 242 } SetDialogChangeEvent(const EventMarker & value)243 void SetDialogChangeEvent(const EventMarker& value) 244 { 245 OnDialogChange_ = value; 246 } 247 SetResizePickerItemHeight(double resizePickerItemHeight)248 void SetResizePickerItemHeight(double resizePickerItemHeight) 249 { 250 resizePickerItemHeight_ = resizePickerItemHeight; 251 } 252 GetResizePickerItemHeight()253 double GetResizePickerItemHeight() const 254 { 255 return resizePickerItemHeight_; 256 } 257 SetResizeFlag(bool resizeFlag)258 void SetResizeFlag(bool resizeFlag) 259 { 260 resizeFlag_ = resizeFlag; 261 } 262 GetResizeFlag()263 bool GetResizeFlag() const 264 { 265 return resizeFlag_; 266 } 267 SetIsShowInDialog(bool isShowInDialog)268 void SetIsShowInDialog(bool isShowInDialog) 269 { 270 isShowInDialog_ = isShowInDialog; 271 } 272 GetIsShowInDialog()273 bool GetIsShowInDialog() const 274 { 275 return isShowInDialog_; 276 } 277 GetOptionCount(RefPtr<FrameNode> & frameNode)278 uint32_t GetOptionCount(RefPtr<FrameNode>& frameNode) 279 { 280 return options_[frameNode].size(); 281 } 282 GetOptionValue(RefPtr<FrameNode> & frameNode,uint32_t index)283 PickerDateF GetOptionValue(RefPtr<FrameNode>& frameNode, uint32_t index) 284 { 285 if (index >= GetOptionCount(frameNode)) { 286 LOGE("index out of range."); 287 return {}; 288 } 289 return options_[frameNode][index]; 290 } 291 GetAllOptions(RefPtr<FrameNode> & frameNode)292 const std::vector<PickerDateF>& GetAllOptions(RefPtr<FrameNode>& frameNode) 293 { 294 return options_[frameNode]; 295 } 296 GetOptions()297 const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& GetOptions() const 298 { 299 return options_; 300 } 301 GetShowCount()302 uint32_t GetShowCount() const 303 { 304 return showCount_; 305 } 306 SetShowCount(uint32_t showCount)307 void SetShowCount(uint32_t showCount) 308 { 309 showCount_ = showCount; 310 } 311 SetDateOrder(std::string dateOrder)312 void SetDateOrder(std::string dateOrder) 313 { 314 dateOrder_ = dateOrder; 315 } 316 GetYearFormatString(uint32_t year)317 static std::string GetYearFormatString(uint32_t year) 318 { 319 return PickerStringFormatter::GetYear(year); 320 } 321 GetMonthFormatString(uint32_t month,bool isLunar,bool isLeap)322 static std::string GetMonthFormatString(uint32_t month, bool isLunar, bool isLeap) 323 { 324 if (isLunar) { 325 return PickerStringFormatter::GetLunarMonth(month, isLeap); 326 } 327 return PickerStringFormatter::GetSolarMonth(month); 328 } 329 GetDayFormatString(uint32_t day,bool isLunar)330 static std::string GetDayFormatString(uint32_t day, bool isLunar) 331 { 332 if (isLunar) { 333 return PickerStringFormatter::GetLunarDay(day); 334 } 335 return PickerStringFormatter::GetSolarDay(day); 336 } 337 338 uint32_t GetLunarMaxDay(uint32_t year, uint32_t month, bool isLeap) const; 339 340 bool GetLunarLeapMonth(uint32_t year, uint32_t& outLeapMonth) const; 341 342 LunarDate SolarToLunar(const PickerDate& date) const; 343 344 PickerDate LunarToSolar(const LunarDate& date) const; 345 346 void UpdateCurrentOffset(float offset); 347 348 void OnDataLinking( 349 const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 350 351 void HandleMonthDaysChange( 352 const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags); 353 354 std::string GetSelectedObject(bool isColumnChange, int status = -1) const; 355 GetSelectDate()356 const LunarDate& GetSelectDate() 357 { 358 return selectedLunar_; 359 } 360 SetSelectDate(const PickerDate & value)361 void SetSelectDate(const PickerDate& value) 362 { 363 selectedDate_ = value; 364 isFiredDateChange_ = firedDateStr_.has_value() && firedDateStr_.value() == GetSelectedObject(false); 365 firedDateStr_.reset(); 366 if (selectedDate_.GetYear() <= 0) { 367 LOGW("selectedDate error"); 368 selectedDate_ = PickerDate::Current(); 369 } 370 AdjustSolarDate(selectedDate_, startDateSolar_, endDateSolar_); 371 selectedLunar_ = SolarToLunar(selectedDate_); 372 } 373 GetSelectedDate()374 const PickerDate& GetSelectedDate() 375 { 376 return selectedDate_; 377 } 378 SetStartDate(const PickerDate & value)379 void SetStartDate(const PickerDate& value) 380 { 381 startDateSolar_ = value; 382 AdjustSolarDate(startDateSolar_, limitStartDate_, limitEndDate_); 383 startDateLunar_ = SolarToLunar(startDateSolar_); 384 } 385 GetStartDateLunar()386 const LunarDate& GetStartDateLunar() 387 { 388 return startDateLunar_; 389 } 390 GetStartDateSolar()391 const PickerDate& GetStartDateSolar() 392 { 393 return startDateSolar_; 394 } 395 SetEndDate(const PickerDate & value)396 void SetEndDate(const PickerDate& value) 397 { 398 endDateSolar_ = value; 399 AdjustSolarDate(endDateSolar_, limitStartDate_, limitEndDate_); 400 endDateLunar_ = SolarToLunar(endDateSolar_); 401 } 402 GetEndDateLunar()403 const LunarDate& GetEndDateLunar() 404 { 405 return endDateLunar_; 406 } 407 GetEndDateSolar()408 const PickerDate& GetEndDateSolar() 409 { 410 return endDateSolar_; 411 } 412 AdjustSolarDate(PickerDate & date,const PickerDate & start,const PickerDate & end)413 void AdjustSolarDate(PickerDate& date, const PickerDate& start, const PickerDate& end) const 414 { 415 if (SolarDateCompare(date, start) < 0) { 416 date = start; 417 return; 418 } 419 if (SolarDateCompare(date, end) > 0) { 420 date = end; 421 } 422 } 423 AdjustSolarDate(PickerDate & date)424 void AdjustSolarDate(PickerDate& date) const 425 { 426 AdjustSolarDate(date, startDateSolar_, endDateSolar_); 427 } 428 SolarDateCompare(const PickerDate & left,const PickerDate & right)429 static int SolarDateCompare(const PickerDate& left, const PickerDate& right) 430 { 431 static const int leftEqualRight = 0; // means left = right 432 static const int leftGreatRight = 1; // means left > right 433 static const int leftLessRight = -1; // means left < right 434 if (left.GetYear() > right.GetYear()) { 435 return leftGreatRight; 436 } 437 if (left.GetYear() < right.GetYear()) { 438 return leftLessRight; 439 } 440 if (left.GetMonth() > right.GetMonth()) { 441 return leftGreatRight; 442 } 443 if (left.GetMonth() < right.GetMonth()) { 444 return leftLessRight; 445 } 446 if (left.GetDay() > right.GetDay()) { 447 return leftGreatRight; 448 } 449 if (left.GetDay() < right.GetDay()) { 450 return leftLessRight; 451 } 452 return leftEqualRight; 453 } 454 HasYearNode()455 bool HasYearNode() const 456 { 457 return yearId_.has_value(); 458 } 459 GetYearId()460 int32_t GetYearId() 461 { 462 if (!yearId_.has_value()) { 463 yearId_ = ElementRegister::GetInstance()->MakeUniqueId(); 464 } 465 return yearId_.value(); 466 } 467 HasMonthNode()468 bool HasMonthNode() const 469 { 470 return monthId_.has_value(); 471 } 472 GetMonthId()473 int32_t GetMonthId() 474 { 475 if (!monthId_.has_value()) { 476 monthId_ = ElementRegister::GetInstance()->MakeUniqueId(); 477 } 478 return monthId_.value(); 479 } 480 HasDayNode()481 bool HasDayNode() const 482 { 483 return dayId_.has_value(); 484 } 485 GetDayId()486 int32_t GetDayId() 487 { 488 if (!dayId_.has_value()) { 489 dayId_ = ElementRegister::GetInstance()->MakeUniqueId(); 490 } 491 return dayId_.value(); 492 } 493 HasMonthDaysNode()494 bool HasMonthDaysNode() const 495 { 496 return monthDaysId_.has_value(); 497 } 498 GetMonthDaysId()499 int32_t GetMonthDaysId() 500 { 501 if (!monthDaysId_.has_value()) { 502 monthDaysId_ = ElementRegister::GetInstance()->MakeUniqueId(); 503 } 504 return monthDaysId_.value(); 505 } 506 HasTitleNode()507 bool HasTitleNode() const 508 { 509 return titleId_.has_value(); 510 } 511 SetTitleId(const int32_t id)512 bool SetTitleId(const int32_t id) 513 { 514 if (HasTitleNode()) { 515 return false; 516 } 517 titleId_ = id; 518 return true; 519 } 520 GetTitleId()521 int32_t GetTitleId() 522 { 523 if (!titleId_.has_value()) { 524 titleId_ = ElementRegister::GetInstance()->MakeUniqueId(); 525 } 526 return titleId_.value(); 527 } 528 HasButtonTitleNode()529 bool HasButtonTitleNode() const 530 { 531 return ButtonTitleId_.has_value(); 532 } 533 GetButtonTitleId()534 int32_t GetButtonTitleId() 535 { 536 if (!ButtonTitleId_.has_value()) { 537 ButtonTitleId_ = ElementRegister::GetInstance()->MakeUniqueId(); 538 } 539 return ButtonTitleId_.value(); 540 } 541 HasDividerNode()542 bool HasDividerNode() const 543 { 544 return DividerId_.has_value(); 545 } 546 GetDividerId()547 int32_t GetDividerId() 548 { 549 if (!DividerId_.has_value()) { 550 DividerId_ = ElementRegister::GetInstance()->MakeUniqueId(); 551 } 552 return DividerId_.value(); 553 } 554 SetBackgroundColor(const Color & color)555 void SetBackgroundColor(const Color& color) 556 { 557 backgroundColor_ = color; 558 } 559 560 static const std::string& GetYear(uint32_t year); 561 562 static const std::string& GetSolarMonth(uint32_t month); 563 564 static const std::string& GetSolarDay(uint32_t day); 565 566 static const std::string& GetLunarMonth(uint32_t month, bool isLeap); 567 568 static const std::string& GetLunarDay(uint32_t day); 569 GetFocusPattern()570 FocusPattern GetFocusPattern() const override 571 { 572 auto pipeline = PipelineBase::GetCurrentContext(); 573 CHECK_NULL_RETURN(pipeline, FocusPattern()); 574 auto pickerTheme = pipeline->GetTheme<PickerTheme>(); 575 CHECK_NULL_RETURN(pickerTheme, FocusPattern()); 576 auto focusColor = pickerTheme->GetFocusColor(); 577 FocusPaintParam focusPaintParams; 578 focusPaintParams.SetPaintColor(focusColor); 579 focusPaintParams.SetPaintWidth(FOCUS_PAINT_WIDTH); 580 return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams }; 581 } 582 583 void ShowTitle(int32_t titleId); 584 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; SetContentRowNode(RefPtr<FrameNode> & contentRowNode)585 void SetContentRowNode(RefPtr<FrameNode>& contentRowNode) 586 { 587 contentRowNode_ = contentRowNode; 588 } SetbuttonTitleNode(RefPtr<FrameNode> & buttonTitleNode)589 void SetbuttonTitleNode(RefPtr<FrameNode>& buttonTitleNode) 590 { 591 buttonTitleNode_ = buttonTitleNode; 592 } 593 SetPickerTag(bool isPicker)594 void SetPickerTag(bool isPicker) 595 { 596 isPicker_ = isPicker; 597 } 598 599 void SetFocusDisable(); 600 void SetFocusEnable(); 601 static const std::string GetFormatString(PickerDateF data); 602 HasUserDefinedDisappearFontFamily(bool isUserDefined)603 void HasUserDefinedDisappearFontFamily(bool isUserDefined) 604 { 605 hasUserDefinedDisappearFontFamily_ = isUserDefined; 606 } 607 GetHasUserDefinedDisappearFontFamily()608 bool GetHasUserDefinedDisappearFontFamily() 609 { 610 return hasUserDefinedDisappearFontFamily_; 611 } 612 HasUserDefinedNormalFontFamily(bool isUserDefined)613 void HasUserDefinedNormalFontFamily(bool isUserDefined) 614 { 615 hasUserDefinedNormalFontFamily_ = isUserDefined; 616 } 617 GetHasUserDefinedNormalFontFamily()618 bool GetHasUserDefinedNormalFontFamily() 619 { 620 return hasUserDefinedNormalFontFamily_; 621 } 622 HasUserDefinedSelectedFontFamily(bool isUserDefined)623 void HasUserDefinedSelectedFontFamily(bool isUserDefined) 624 { 625 hasUserDefinedSelectedFontFamily_ = isUserDefined; 626 } 627 GetHasUserDefinedSelectedFontFamily()628 bool GetHasUserDefinedSelectedFontFamily() 629 { 630 return hasUserDefinedSelectedFontFamily_; 631 } 632 updateFontConfigurationEvent(const std::function<void ()> & closeDialogEvent)633 void updateFontConfigurationEvent(const std::function<void()>& closeDialogEvent) 634 { 635 closeDialogEvent_ = closeDialogEvent; 636 } 637 GetTextProperties()638 const PickerTextProperties& GetTextProperties() const 639 { 640 return textProperties_; 641 } 642 SetTextProperties(const PickerTextProperties & properties)643 void SetTextProperties(const PickerTextProperties& properties) 644 { 645 textProperties_ = properties; 646 if (properties.disappearTextStyle_.fontSize.has_value() && properties.disappearTextStyle_.fontSize->IsValid()) { 647 isUserSetGradientFont_ = true; 648 gradientHeight_ = properties.disappearTextStyle_.fontSize.value(); 649 } 650 651 if (properties.normalTextStyle_.fontSize.has_value() && properties.normalTextStyle_.fontSize->IsValid()) { 652 isUserSetGradientFont_ = true; 653 gradientHeight_ = std::max(properties.normalTextStyle_.fontSize.value(), gradientHeight_); 654 } 655 656 if (properties.selectedTextStyle_.fontSize.has_value() && properties.selectedTextStyle_.fontSize->IsValid()) { 657 isUserSetDividerSpacingFont_ = true; 658 dividerSpacing_ = properties.selectedTextStyle_.fontSize.value(); 659 } 660 } 661 GetIsUserSetDividerSpacingFont()662 bool GetIsUserSetDividerSpacingFont() 663 { 664 return isUserSetDividerSpacingFont_; 665 } 666 GetIsUserSetGradientFont()667 bool GetIsUserSetGradientFont() 668 { 669 return isUserSetGradientFont_; 670 } 671 GetDividerSpacing()672 Dimension GetDividerSpacing() 673 { 674 return dividerSpacing_; 675 } 676 GetGradientHeight()677 Dimension GetGradientHeight() 678 { 679 return gradientHeight_; 680 } 681 SetPaintDividerSpacing(float & value)682 void SetPaintDividerSpacing(float& value) 683 { 684 paintDividerSpacing_ = value; 685 } 686 GetPaintDividerSpacing()687 float GetPaintDividerSpacing() 688 { 689 return paintDividerSpacing_; 690 } 691 SetUserDefinedOpacity(double opacity)692 void SetUserDefinedOpacity(double opacity) 693 { 694 curOpacity_ = opacity; 695 } 696 697 private: 698 void OnModifyDone() override; 699 void OnAttachToFrameNode() override; 700 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 701 static void Init(); 702 void InitDisabled(); 703 void GetInnerFocusPaintRect(RoundRect& paintRect); 704 void PaintFocusState(); 705 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 706 bool OnKeyEvent(const KeyEvent& event); 707 bool HandleDirectionKey(KeyCode code); 708 PickerDate GetCurrentDateByMonthDaysColumn() const; 709 PickerDate GetCurrentDateByYearMonthDayColumn() const; 710 void OrderCurrentDateByYearMonthDayColumn( 711 RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const; 712 void FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn); 713 void UpdateTitleTextColor(const RefPtr<FrameNode>& buttonTitleNode, const RefPtr<PickerTheme>& pickerTheme); 714 void FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn); 715 void AdjustSolarStartEndDate(); 716 void AdjustLunarStartEndDate(); 717 RefPtr<ClickEvent> clickEventListener_; 718 bool enabled_ = true; 719 int32_t focusKeyID_ = 0; 720 std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>> options_; 721 uint32_t showCount_ = 0; 722 std::string dateOrder_ = ""; 723 std::vector<WeakPtr<FrameNode>> datePickerColumns_; 724 bool lunar_ = false; 725 bool showMonthDays_ = false; 726 bool showTime_ = false; 727 Color backgroundColor_ = Color::WHITE; 728 std::optional<int32_t> yearId_; 729 std::optional<int32_t> monthId_; 730 std::optional<int32_t> dayId_; 731 std::optional<int32_t> monthDaysId_; 732 std::optional<int32_t> dateNodeId_; 733 std::optional<int32_t> titleId_; 734 std::optional<int32_t> ButtonTitleId_; 735 std::optional<int32_t> DividerId_; 736 double resizePickerItemHeight_ = 0.0; 737 bool resizeFlag_ = false; 738 bool isShowInDialog_ = false; 739 EventMarker OnDialogAccept_; 740 EventMarker OnDialogCancel_; 741 EventMarker OnDialogChange_; 742 WeakPtr<FrameNode> weakButtonConfirm_; 743 WeakPtr<FrameNode> weakButtonCancel_; 744 WeakPtr<FrameNode> weakLunarSwitchText_; 745 PickerDate startDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document. 746 LunarDate startDateLunar_; 747 PickerDate endDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document. 748 LunarDate endDateLunar_; 749 PickerDate selectedDate_ = PickerDate::Current(); 750 LunarDate selectedLunar_; 751 PickerDate startDefaultDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document. 752 PickerDate endDefaultDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document. 753 const PickerDate limitStartDate_ = PickerDate(1900, 1, 31); 754 const PickerDate limitEndDate_ = PickerDate(2100, 12, 31); 755 static bool inited_; 756 static const std::string empty_; 757 static const PickerDateF emptyPickerDate_; 758 static std::unordered_map<uint32_t, std::string> years_; // year from 1900 to 2100,count is 201 759 static std::unordered_map<uint32_t, std::string> solarMonths_; // solar month from 1 to 12,count is 12 760 static std::unordered_map<uint32_t, std::string> solarDays_; // solar day from 1 to 31, count is 31 761 static std::unordered_map<uint32_t, std::string> lunarMonths_; // lunar month from 1 to 24, count is 24 762 static std::unordered_map<uint32_t, std::string> lunarDays_; // lunar day from 1 to 30, count is 30 763 static std::vector<std::string> tagOrder_; // year month day tag order 764 static std::vector<std::string> localizedMonths_; 765 WeakPtr<FrameNode> contentRowNode_; 766 WeakPtr<FrameNode> buttonTitleNode_; 767 bool isPicker_ = false; 768 bool isFiredDateChange_ = false; 769 bool isForceUpdate_ = false; 770 std::optional<std::string> firedDateStr_; 771 772 bool hasUserDefinedDisappearFontFamily_ = false; 773 bool hasUserDefinedNormalFontFamily_ = false; 774 bool hasUserDefinedSelectedFontFamily_ = false; 775 std::function<void()> closeDialogEvent_; 776 bool isUserSetDividerSpacingFont_ = false; 777 bool isUserSetGradientFont_ = false; 778 Dimension gradientHeight_; 779 Dimension dividerSpacing_; 780 float paintDividerSpacing_ = 1.0f; 781 PickerTextProperties textProperties_; 782 double curOpacity_ = 1.0; 783 784 ACE_DISALLOW_COPY_AND_MOVE(DatePickerPattern); 785 }; 786 } // namespace OHOS::Ace::NG 787 788 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H 789