1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#include "components/ui_dialog.h" 17a3e0fd82Sopenharmony_ci#include "common/screen.h" 18a3e0fd82Sopenharmony_ci#include "common/typed_text.h" 19a3e0fd82Sopenharmony_ci#if ENABLE_DEBUG 20a3e0fd82Sopenharmony_ci#include "gfx_utils/graphic_assert.h" 21a3e0fd82Sopenharmony_ci#endif 22a3e0fd82Sopenharmony_ci#include "gfx_utils/graphic_log.h" 23a3e0fd82Sopenharmony_ci#if ENABLE_WINDOW 24a3e0fd82Sopenharmony_ci#include "window/window.h" 25a3e0fd82Sopenharmony_ci#endif 26a3e0fd82Sopenharmony_ci 27a3e0fd82Sopenharmony_ci#if ENABLE_WINDOW 28a3e0fd82Sopenharmony_cinamespace OHOS { 29a3e0fd82Sopenharmony_ciclass UIDialogLabelButton : public UILabelButton { 30a3e0fd82Sopenharmony_cipublic: 31a3e0fd82Sopenharmony_ci explicit UIDialogLabelButton(UIDialog* dialog) 32a3e0fd82Sopenharmony_ci { 33a3e0fd82Sopenharmony_ci dialog_ = dialog; 34a3e0fd82Sopenharmony_ci } 35a3e0fd82Sopenharmony_ci virtual ~UIDialogLabelButton() {} 36a3e0fd82Sopenharmony_ci virtual bool OnClickEvent(const ClickEvent& event) 37a3e0fd82Sopenharmony_ci { 38a3e0fd82Sopenharmony_ci bool ret = true; 39a3e0fd82Sopenharmony_ci if (dialog_ != nullptr) { 40a3e0fd82Sopenharmony_ci dialog_->DestroyWindow(); 41a3e0fd82Sopenharmony_ci dialog_->isShowing_ = false; 42a3e0fd82Sopenharmony_ci } 43a3e0fd82Sopenharmony_ci if (onClickListener_ != nullptr) { 44a3e0fd82Sopenharmony_ci ret = onClickListener_->OnClick(*this, event); 45a3e0fd82Sopenharmony_ci } 46a3e0fd82Sopenharmony_ci return ret; 47a3e0fd82Sopenharmony_ci } 48a3e0fd82Sopenharmony_ciprivate: 49a3e0fd82Sopenharmony_ci UIDialog* dialog_; 50a3e0fd82Sopenharmony_ci}; 51a3e0fd82Sopenharmony_ci 52a3e0fd82Sopenharmony_ciclass UIDialogClickListener : public UIView::OnClickListener { 53a3e0fd82Sopenharmony_cipublic: 54a3e0fd82Sopenharmony_ci explicit UIDialogClickListener(UIDialog* dialog) 55a3e0fd82Sopenharmony_ci { 56a3e0fd82Sopenharmony_ci dialog_ = dialog; 57a3e0fd82Sopenharmony_ci } 58a3e0fd82Sopenharmony_ci virtual ~UIDialogClickListener() {} 59a3e0fd82Sopenharmony_ci bool OnClick(UIView& view, const ClickEvent& event) override 60a3e0fd82Sopenharmony_ci { 61a3e0fd82Sopenharmony_ci bool ret = true; 62a3e0fd82Sopenharmony_ci if ((dialog_ != nullptr) && (dialog_->dialogLayer_ != nullptr) && 63a3e0fd82Sopenharmony_ci !dialog_->dialogLayer_->GetRect().IsContains(event.GetCurrentPos())) { 64a3e0fd82Sopenharmony_ci if (dialog_->enableAutoCancel_) { 65a3e0fd82Sopenharmony_ci dialog_->DestroyWindow(); 66a3e0fd82Sopenharmony_ci dialog_->isShowing_ = false; 67a3e0fd82Sopenharmony_ci } 68a3e0fd82Sopenharmony_ci if (dialog_->onCancelListener_ != nullptr) { 69a3e0fd82Sopenharmony_ci ret = dialog_->onCancelListener_->OnClick(view, event); 70a3e0fd82Sopenharmony_ci } 71a3e0fd82Sopenharmony_ci } 72a3e0fd82Sopenharmony_ci return ret; 73a3e0fd82Sopenharmony_ci } 74a3e0fd82Sopenharmony_ciprivate: 75a3e0fd82Sopenharmony_ci UIDialog* dialog_; 76a3e0fd82Sopenharmony_ci}; 77a3e0fd82Sopenharmony_ci 78a3e0fd82Sopenharmony_ciUIDialog::UIDialog() 79a3e0fd82Sopenharmony_ci : isShowing_(false), 80a3e0fd82Sopenharmony_ci enableAutoCancel_(false), 81a3e0fd82Sopenharmony_ci buttonNum_(0), 82a3e0fd82Sopenharmony_ci title_(nullptr), 83a3e0fd82Sopenharmony_ci text_(nullptr), 84a3e0fd82Sopenharmony_ci button1_(nullptr), 85a3e0fd82Sopenharmony_ci button2_(nullptr), 86a3e0fd82Sopenharmony_ci button3_(nullptr), 87a3e0fd82Sopenharmony_ci dialogLayer_(nullptr), 88a3e0fd82Sopenharmony_ci windowRootView_(nullptr), 89a3e0fd82Sopenharmony_ci onCancelListener_(nullptr), 90a3e0fd82Sopenharmony_ci dialogClickListener_(nullptr), 91a3e0fd82Sopenharmony_ci window_(nullptr), 92a3e0fd82Sopenharmony_ci line1_(nullptr), 93a3e0fd82Sopenharmony_ci line2_(nullptr), 94a3e0fd82Sopenharmony_ci titleText_(nullptr), 95a3e0fd82Sopenharmony_ci textText_(nullptr) 96a3e0fd82Sopenharmony_ci{ 97a3e0fd82Sopenharmony_ci uint16_t screenWidth = Screen::GetInstance().GetWidth(); 98a3e0fd82Sopenharmony_ci uint16_t screenHeight = Screen::GetInstance().GetHeight(); 99a3e0fd82Sopenharmony_ci // 100: calculate percentage 100a3e0fd82Sopenharmony_ci widthMax_ = screenWidth * MAX_WIDTH_PERCENT / 100; 101a3e0fd82Sopenharmony_ci // 100: calculate percentage 102a3e0fd82Sopenharmony_ci heightMax_ = screenHeight * MAX_HEIGHT_PERCENT / 100; 103a3e0fd82Sopenharmony_ci colorType1_ = Color::White(); 104a3e0fd82Sopenharmony_ci colorType2_ = Color::White(); 105a3e0fd82Sopenharmony_ci colorType3_ = Color::White(); 106a3e0fd82Sopenharmony_ci} 107a3e0fd82Sopenharmony_ci 108a3e0fd82Sopenharmony_ciUIDialog::~UIDialog() 109a3e0fd82Sopenharmony_ci{ 110a3e0fd82Sopenharmony_ci onCancelListener_ = nullptr; 111a3e0fd82Sopenharmony_ci if (dialogLayer_ != nullptr) { 112a3e0fd82Sopenharmony_ci dialogLayer_->RemoveAll(); 113a3e0fd82Sopenharmony_ci delete dialogLayer_; 114a3e0fd82Sopenharmony_ci dialogLayer_ = nullptr; 115a3e0fd82Sopenharmony_ci } 116a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 117a3e0fd82Sopenharmony_ci delete title_; 118a3e0fd82Sopenharmony_ci title_ = nullptr; 119a3e0fd82Sopenharmony_ci } 120a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 121a3e0fd82Sopenharmony_ci delete text_; 122a3e0fd82Sopenharmony_ci text_ = nullptr; 123a3e0fd82Sopenharmony_ci } 124a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 125a3e0fd82Sopenharmony_ci delete button1_; 126a3e0fd82Sopenharmony_ci button1_ = nullptr; 127a3e0fd82Sopenharmony_ci } 128a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 129a3e0fd82Sopenharmony_ci delete button2_; 130a3e0fd82Sopenharmony_ci button2_ = nullptr; 131a3e0fd82Sopenharmony_ci } 132a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 133a3e0fd82Sopenharmony_ci delete button3_; 134a3e0fd82Sopenharmony_ci button3_ = nullptr; 135a3e0fd82Sopenharmony_ci } 136a3e0fd82Sopenharmony_ci if (line1_ != nullptr) { 137a3e0fd82Sopenharmony_ci delete line1_; 138a3e0fd82Sopenharmony_ci line1_ = nullptr; 139a3e0fd82Sopenharmony_ci } 140a3e0fd82Sopenharmony_ci if (line2_ != nullptr) { 141a3e0fd82Sopenharmony_ci delete line2_; 142a3e0fd82Sopenharmony_ci line2_ = nullptr; 143a3e0fd82Sopenharmony_ci } 144a3e0fd82Sopenharmony_ci if ((windowRootView_ != nullptr) && !RootView::DestroyWindowRootView(windowRootView_)) { 145a3e0fd82Sopenharmony_ci windowRootView_ = nullptr; 146a3e0fd82Sopenharmony_ci } 147a3e0fd82Sopenharmony_ci if (dialogClickListener_ != nullptr) { 148a3e0fd82Sopenharmony_ci delete dialogClickListener_; 149a3e0fd82Sopenharmony_ci dialogClickListener_ = nullptr; 150a3e0fd82Sopenharmony_ci } 151a3e0fd82Sopenharmony_ci} 152a3e0fd82Sopenharmony_ci 153a3e0fd82Sopenharmony_civoid UIDialog::SetTitle(const char* title) 154a3e0fd82Sopenharmony_ci{ 155a3e0fd82Sopenharmony_ci if (title == nullptr) { 156a3e0fd82Sopenharmony_ci return; 157a3e0fd82Sopenharmony_ci } 158a3e0fd82Sopenharmony_ci titleText_ = title; 159a3e0fd82Sopenharmony_ci} 160a3e0fd82Sopenharmony_ci 161a3e0fd82Sopenharmony_civoid UIDialog::SetText(const char* text) 162a3e0fd82Sopenharmony_ci{ 163a3e0fd82Sopenharmony_ci if (text == nullptr) { 164a3e0fd82Sopenharmony_ci return; 165a3e0fd82Sopenharmony_ci } 166a3e0fd82Sopenharmony_ci textText_ = text; 167a3e0fd82Sopenharmony_ci} 168a3e0fd82Sopenharmony_ci 169a3e0fd82Sopenharmony_civoid UIDialog::SetButton(DialogButtonType buttonType, const char* text, UIView::OnClickListener* listener) 170a3e0fd82Sopenharmony_ci{ 171a3e0fd82Sopenharmony_ci switch (buttonType) { 172a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_LEFT: 173a3e0fd82Sopenharmony_ci if (button1_ == nullptr) { 174a3e0fd82Sopenharmony_ci button1_ = new UIDialogLabelButton(this); 175a3e0fd82Sopenharmony_ci if (button1_ == nullptr) { 176a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIDialogLabelButton fail"); 177a3e0fd82Sopenharmony_ci return; 178a3e0fd82Sopenharmony_ci } 179a3e0fd82Sopenharmony_ci button1_->SetViewId(BUTTON1_ID); 180a3e0fd82Sopenharmony_ci AddButton(buttonType, button1_, text, listener); 181a3e0fd82Sopenharmony_ci } else { 182a3e0fd82Sopenharmony_ci button1_->SetText(text); 183a3e0fd82Sopenharmony_ci button1_->SetOnClickListener(listener); 184a3e0fd82Sopenharmony_ci } 185a3e0fd82Sopenharmony_ci break; 186a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_MID: 187a3e0fd82Sopenharmony_ci if (button2_ == nullptr) { 188a3e0fd82Sopenharmony_ci button2_ = new UIDialogLabelButton(this); 189a3e0fd82Sopenharmony_ci if (button2_ == nullptr) { 190a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIDialogLabelButton fail"); 191a3e0fd82Sopenharmony_ci return; 192a3e0fd82Sopenharmony_ci } 193a3e0fd82Sopenharmony_ci button2_->SetViewId(BUTTON2_ID); 194a3e0fd82Sopenharmony_ci AddButton(buttonType, button2_, text, listener); 195a3e0fd82Sopenharmony_ci } else { 196a3e0fd82Sopenharmony_ci button2_->SetText(text); 197a3e0fd82Sopenharmony_ci button2_->SetOnClickListener(listener); 198a3e0fd82Sopenharmony_ci } 199a3e0fd82Sopenharmony_ci break; 200a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_RIGHT: 201a3e0fd82Sopenharmony_ci if (button3_ == nullptr) { 202a3e0fd82Sopenharmony_ci button3_ = new UIDialogLabelButton(this); 203a3e0fd82Sopenharmony_ci if (button3_ == nullptr) { 204a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIDialogLabelButton fail"); 205a3e0fd82Sopenharmony_ci return; 206a3e0fd82Sopenharmony_ci } 207a3e0fd82Sopenharmony_ci AddButton(buttonType, button3_, text, listener); 208a3e0fd82Sopenharmony_ci } else { 209a3e0fd82Sopenharmony_ci button3_->SetText(text); 210a3e0fd82Sopenharmony_ci button3_->SetOnClickListener(listener); 211a3e0fd82Sopenharmony_ci } 212a3e0fd82Sopenharmony_ci break; 213a3e0fd82Sopenharmony_ci default: 214a3e0fd82Sopenharmony_ci break; 215a3e0fd82Sopenharmony_ci } 216a3e0fd82Sopenharmony_ci} 217a3e0fd82Sopenharmony_ci 218a3e0fd82Sopenharmony_civoid UIDialog::AddButton(DialogButtonType buttonType, 219a3e0fd82Sopenharmony_ci UILabelButton* button, 220a3e0fd82Sopenharmony_ci const char* text, 221a3e0fd82Sopenharmony_ci UIView::OnClickListener* listener) 222a3e0fd82Sopenharmony_ci{ 223a3e0fd82Sopenharmony_ci buttonNum_++; 224a3e0fd82Sopenharmony_ci button->SetText(text); 225a3e0fd82Sopenharmony_ci button->SetOnClickListener(listener); 226a3e0fd82Sopenharmony_ci button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_FONT_SIZE); 227a3e0fd82Sopenharmony_ci button->SetTextColor(Color::Blue()); 228a3e0fd82Sopenharmony_ci button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::White().full, UIButton::ButtonState::RELEASED); 229a3e0fd82Sopenharmony_ci button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::ButtonState::PRESSED); 230a3e0fd82Sopenharmony_ci button->SetStyleForState(STYLE_BACKGROUND_OPA, BUTTON_PRESS_OPA, UIButton::ButtonState::PRESSED); 231a3e0fd82Sopenharmony_ci button->SetStyleForState(STYLE_BORDER_WIDTH, 0, UIButton::ButtonState::RELEASED); 232a3e0fd82Sopenharmony_ci button->SetStyleForState(STYLE_BORDER_WIDTH, 0, UIButton::ButtonState::PRESSED); 233a3e0fd82Sopenharmony_ci button->SetHeight(BUTTON_HEIGHT); 234a3e0fd82Sopenharmony_ci} 235a3e0fd82Sopenharmony_ci 236a3e0fd82Sopenharmony_civoid UIDialog::Show() 237a3e0fd82Sopenharmony_ci{ 238a3e0fd82Sopenharmony_ci if (isShowing_) { 239a3e0fd82Sopenharmony_ci return; 240a3e0fd82Sopenharmony_ci } 241a3e0fd82Sopenharmony_ci SetTitleLabel(); 242a3e0fd82Sopenharmony_ci SetTextLabel(); 243a3e0fd82Sopenharmony_ci InitDialog(); 244a3e0fd82Sopenharmony_ci AddComponents(); 245a3e0fd82Sopenharmony_ci MeasureSize(); 246a3e0fd82Sopenharmony_ci Layout(); 247a3e0fd82Sopenharmony_ci CreateDialogWindow(); 248a3e0fd82Sopenharmony_ci window_->Show(); 249a3e0fd82Sopenharmony_ci isShowing_ = true; 250a3e0fd82Sopenharmony_ci} 251a3e0fd82Sopenharmony_ci 252a3e0fd82Sopenharmony_civoid UIDialog::SetTitleLabel() 253a3e0fd82Sopenharmony_ci{ 254a3e0fd82Sopenharmony_ci if (titleText_ == nullptr) { 255a3e0fd82Sopenharmony_ci return; 256a3e0fd82Sopenharmony_ci } 257a3e0fd82Sopenharmony_ci if (title_ == nullptr) { 258a3e0fd82Sopenharmony_ci title_ = new UILabel(); 259a3e0fd82Sopenharmony_ci if (title_ == nullptr) { 260a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UILabel fail"); 261a3e0fd82Sopenharmony_ci return; 262a3e0fd82Sopenharmony_ci } 263a3e0fd82Sopenharmony_ci title_->SetViewId(TITLE_ID); 264a3e0fd82Sopenharmony_ci title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); 265a3e0fd82Sopenharmony_ci title_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT); 266a3e0fd82Sopenharmony_ci title_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); 267a3e0fd82Sopenharmony_ci title_->SetStyle(STYLE_TEXT_OPA, TITLE_TEXT_OPA); 268a3e0fd82Sopenharmony_ci title_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); 269a3e0fd82Sopenharmony_ci } 270a3e0fd82Sopenharmony_ci title_->SetText(titleText_); 271a3e0fd82Sopenharmony_ci} 272a3e0fd82Sopenharmony_ci 273a3e0fd82Sopenharmony_civoid UIDialog::SetTextLabel() 274a3e0fd82Sopenharmony_ci{ 275a3e0fd82Sopenharmony_ci if (textText_ == nullptr) { 276a3e0fd82Sopenharmony_ci return; 277a3e0fd82Sopenharmony_ci } 278a3e0fd82Sopenharmony_ci if (text_ == nullptr) { 279a3e0fd82Sopenharmony_ci text_ = new UILabel(); 280a3e0fd82Sopenharmony_ci if (text_ == nullptr) { 281a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UILabel fail"); 282a3e0fd82Sopenharmony_ci return; 283a3e0fd82Sopenharmony_ci } 284a3e0fd82Sopenharmony_ci text_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_FONT_SIZE); 285a3e0fd82Sopenharmony_ci text_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); 286a3e0fd82Sopenharmony_ci text_->SetStyle(STYLE_TEXT_OPA, TITLE_TEXT_OPA); 287a3e0fd82Sopenharmony_ci text_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); 288a3e0fd82Sopenharmony_ci } 289a3e0fd82Sopenharmony_ci text_->SetText(textText_); 290a3e0fd82Sopenharmony_ci} 291a3e0fd82Sopenharmony_ci 292a3e0fd82Sopenharmony_civoid UIDialog::InitDialog() 293a3e0fd82Sopenharmony_ci{ 294a3e0fd82Sopenharmony_ci if (dialogLayer_ == nullptr) { 295a3e0fd82Sopenharmony_ci dialogLayer_ = new UIViewGroup(); 296a3e0fd82Sopenharmony_ci if (dialogLayer_ == nullptr) { 297a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIViewGroup fail"); 298a3e0fd82Sopenharmony_ci return; 299a3e0fd82Sopenharmony_ci } 300a3e0fd82Sopenharmony_ci dialogLayer_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); 301a3e0fd82Sopenharmony_ci } 302a3e0fd82Sopenharmony_ci if (windowRootView_ == nullptr) { 303a3e0fd82Sopenharmony_ci windowRootView_ = RootView::GetWindowRootView(); 304a3e0fd82Sopenharmony_ci windowRootView_->SetWidth(Screen::GetInstance().GetWidth()); 305a3e0fd82Sopenharmony_ci windowRootView_->SetHeight(Screen::GetInstance().GetHeight()); 306a3e0fd82Sopenharmony_ci windowRootView_->SetTouchable(true); 307a3e0fd82Sopenharmony_ci windowRootView_->Add(dialogLayer_); 308a3e0fd82Sopenharmony_ci } 309a3e0fd82Sopenharmony_ci if (dialogClickListener_ == nullptr) { 310a3e0fd82Sopenharmony_ci dialogClickListener_ = new UIDialogClickListener(this); 311a3e0fd82Sopenharmony_ci if (dialogClickListener_ == nullptr) { 312a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIDialogClickListener fail"); 313a3e0fd82Sopenharmony_ci return; 314a3e0fd82Sopenharmony_ci } 315a3e0fd82Sopenharmony_ci windowRootView_->SetOnClickListener(dialogClickListener_); 316a3e0fd82Sopenharmony_ci } 317a3e0fd82Sopenharmony_ci} 318a3e0fd82Sopenharmony_ci 319a3e0fd82Sopenharmony_civoid UIDialog::AddComponents() 320a3e0fd82Sopenharmony_ci{ 321a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 322a3e0fd82Sopenharmony_ci dialogLayer_->Add(title_); 323a3e0fd82Sopenharmony_ci } 324a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 325a3e0fd82Sopenharmony_ci dialogLayer_->Add(text_); 326a3e0fd82Sopenharmony_ci } 327a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 328a3e0fd82Sopenharmony_ci dialogLayer_->Add(button1_); 329a3e0fd82Sopenharmony_ci } 330a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 331a3e0fd82Sopenharmony_ci dialogLayer_->Add(button2_); 332a3e0fd82Sopenharmony_ci } 333a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 334a3e0fd82Sopenharmony_ci dialogLayer_->Add(button3_); 335a3e0fd82Sopenharmony_ci } 336a3e0fd82Sopenharmony_ci if (buttonNum_ > 1) { 337a3e0fd82Sopenharmony_ci line1_ = new UIView(); 338a3e0fd82Sopenharmony_ci if (line1_ == nullptr) { 339a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIView fail"); 340a3e0fd82Sopenharmony_ci return; 341a3e0fd82Sopenharmony_ci } 342a3e0fd82Sopenharmony_ci line1_->SetHeight(LINE_HEIGHT); 343a3e0fd82Sopenharmony_ci line1_->SetWidth(LINE_WIDTH); 344a3e0fd82Sopenharmony_ci line1_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); 345a3e0fd82Sopenharmony_ci line1_->SetStyle(STYLE_BACKGROUND_OPA, LINE_OPA); 346a3e0fd82Sopenharmony_ci dialogLayer_->Add(line1_); 347a3e0fd82Sopenharmony_ci } 348a3e0fd82Sopenharmony_ci if (buttonNum_ == 3) { // 3: three buttons 349a3e0fd82Sopenharmony_ci line2_ = new UIView(); 350a3e0fd82Sopenharmony_ci if (line2_ == nullptr) { 351a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIView fail"); 352a3e0fd82Sopenharmony_ci return; 353a3e0fd82Sopenharmony_ci } 354a3e0fd82Sopenharmony_ci line2_->SetHeight(LINE_HEIGHT); 355a3e0fd82Sopenharmony_ci line2_->SetWidth(LINE_WIDTH); 356a3e0fd82Sopenharmony_ci line2_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); 357a3e0fd82Sopenharmony_ci line2_->SetStyle(STYLE_BACKGROUND_OPA, LINE_OPA); 358a3e0fd82Sopenharmony_ci dialogLayer_->Add(line2_); 359a3e0fd82Sopenharmony_ci } 360a3e0fd82Sopenharmony_ci} 361a3e0fd82Sopenharmony_ci 362a3e0fd82Sopenharmony_civoid UIDialog::MeasureSize() 363a3e0fd82Sopenharmony_ci{ 364a3e0fd82Sopenharmony_ci uint16_t width = MeasureMaxWidth(); 365a3e0fd82Sopenharmony_ci uint16_t height = 0; 366a3e0fd82Sopenharmony_ci 367a3e0fd82Sopenharmony_ci if (buttonNum_ > 0) { 368a3e0fd82Sopenharmony_ci // 2: there are 2 paddings horizontally 369a3e0fd82Sopenharmony_ci uint16_t buttonWidth = (width - 2 * BUTTON_PADDING - (buttonNum_ - 1) * BUTTON_MID_PADDING) / buttonNum_; 370a3e0fd82Sopenharmony_ci // 2: there are 2 paddings horizontally 371a3e0fd82Sopenharmony_ci width = static_cast<uint32_t>(buttonWidth) * buttonNum_ + (buttonNum_ - 1) * BUTTON_MID_PADDING + 372a3e0fd82Sopenharmony_ci 2 * BUTTON_PADDING; 373a3e0fd82Sopenharmony_ci height += BUTTON_TOTAL_HEIGHT; 374a3e0fd82Sopenharmony_ci height += TEXT_BUTTON_PADDING; 375a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 376a3e0fd82Sopenharmony_ci button1_->SetWidth(buttonWidth); 377a3e0fd82Sopenharmony_ci } 378a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 379a3e0fd82Sopenharmony_ci button2_->SetWidth(buttonWidth); 380a3e0fd82Sopenharmony_ci } 381a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 382a3e0fd82Sopenharmony_ci button3_->SetWidth(buttonWidth); 383a3e0fd82Sopenharmony_ci } 384a3e0fd82Sopenharmony_ci } else { 385a3e0fd82Sopenharmony_ci height += PADDING; 386a3e0fd82Sopenharmony_ci } 387a3e0fd82Sopenharmony_ci 388a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 389a3e0fd82Sopenharmony_ci title_->SetWidth(width - 2 * PADDING); // 2: there are 2 paddings horizontally 390a3e0fd82Sopenharmony_ci height += TITLE_TOTAL_HEIGHT; 391a3e0fd82Sopenharmony_ci } else { 392a3e0fd82Sopenharmony_ci height += PADDING; 393a3e0fd82Sopenharmony_ci } 394a3e0fd82Sopenharmony_ci 395a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 396a3e0fd82Sopenharmony_ci text_->SetWidth(width - 2 * PADDING); // 2: there are 2 paddings horizontally 397a3e0fd82Sopenharmony_ci uint16_t textHightMax = heightMax_ - height; 398a3e0fd82Sopenharmony_ci if (text_->GetTextHeight() < textHightMax) { 399a3e0fd82Sopenharmony_ci text_->SetHeight(text_->GetTextHeight()); 400a3e0fd82Sopenharmony_ci } else { 401a3e0fd82Sopenharmony_ci text_->SetHeight(textHightMax); 402a3e0fd82Sopenharmony_ci text_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); 403a3e0fd82Sopenharmony_ci } 404a3e0fd82Sopenharmony_ci height += text_->GetHeight(); 405a3e0fd82Sopenharmony_ci } 406a3e0fd82Sopenharmony_ci 407a3e0fd82Sopenharmony_ci uint16_t dialogHeight = height; 408a3e0fd82Sopenharmony_ci dialogLayer_->SetHeight(dialogHeight); 409a3e0fd82Sopenharmony_ci dialogLayer_->SetWidth(width); 410a3e0fd82Sopenharmony_ci} 411a3e0fd82Sopenharmony_ci 412a3e0fd82Sopenharmony_ciuint16_t UIDialog::MeasureMaxWidth() 413a3e0fd82Sopenharmony_ci{ 414a3e0fd82Sopenharmony_ci uint16_t titleWidth = 0; 415a3e0fd82Sopenharmony_ci uint16_t textWidth = 0; 416a3e0fd82Sopenharmony_ci uint16_t buttonTotalWidth = 0; 417a3e0fd82Sopenharmony_ci 418a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 419a3e0fd82Sopenharmony_ci titleWidth = MeasureTitleWidth(); 420a3e0fd82Sopenharmony_ci titleWidth += 2 * PADDING; // 2: there are 2 paddings horizontally 421a3e0fd82Sopenharmony_ci } 422a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 423a3e0fd82Sopenharmony_ci textWidth = MeasureTextWidth(); 424a3e0fd82Sopenharmony_ci textWidth += 2 * PADDING; // 2: there are 2 paddings horizontally 425a3e0fd82Sopenharmony_ci } 426a3e0fd82Sopenharmony_ci if (buttonNum_ > 0) { 427a3e0fd82Sopenharmony_ci buttonTotalWidth = 428a3e0fd82Sopenharmony_ci static_cast<uint32_t>(MeasureButtonWidth()) * buttonNum_ + (buttonNum_ - 1) * BUTTON_MID_PADDING; 429a3e0fd82Sopenharmony_ci buttonTotalWidth += 2 * BUTTON_PADDING; // 2: there are 2 paddings horizontally 430a3e0fd82Sopenharmony_ci } 431a3e0fd82Sopenharmony_ci return MATH_MAX(titleWidth, MATH_MAX(textWidth, buttonTotalWidth)); 432a3e0fd82Sopenharmony_ci} 433a3e0fd82Sopenharmony_ci 434a3e0fd82Sopenharmony_ciuint16_t UIDialog::MeasureTitleWidth() 435a3e0fd82Sopenharmony_ci{ 436a3e0fd82Sopenharmony_ci uint16_t titleWidth = 0; 437a3e0fd82Sopenharmony_ci uint16_t widthMaxNoPadding = widthMax_ - 2 * PADDING; // 2: there are 2 paddings horizontally 438a3e0fd82Sopenharmony_ci title_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); 439a3e0fd82Sopenharmony_ci if (title_->GetTextWidth() > widthMaxNoPadding) { 440a3e0fd82Sopenharmony_ci titleWidth = widthMaxNoPadding; 441a3e0fd82Sopenharmony_ci title_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); 442a3e0fd82Sopenharmony_ci } else { 443a3e0fd82Sopenharmony_ci titleWidth = title_->GetTextWidth(); 444a3e0fd82Sopenharmony_ci } 445a3e0fd82Sopenharmony_ci title_->SetHeight(title_->GetTextHeight()); 446a3e0fd82Sopenharmony_ci return titleWidth; 447a3e0fd82Sopenharmony_ci} 448a3e0fd82Sopenharmony_ci 449a3e0fd82Sopenharmony_ciuint16_t UIDialog::MeasureTextWidth() 450a3e0fd82Sopenharmony_ci{ 451a3e0fd82Sopenharmony_ci uint16_t textWidth = 0; 452a3e0fd82Sopenharmony_ci uint16_t widthMaxNoPadding = widthMax_ - 2 * PADDING; // 2: there are 2 paddings horizontally 453a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 454a3e0fd82Sopenharmony_ci text_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT); 455a3e0fd82Sopenharmony_ci } else { 456a3e0fd82Sopenharmony_ci text_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); 457a3e0fd82Sopenharmony_ci } 458a3e0fd82Sopenharmony_ci text_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); 459a3e0fd82Sopenharmony_ci textWidth = text_->GetTextWidth(); 460a3e0fd82Sopenharmony_ci if (text_->GetTextWidth() > widthMaxNoPadding) { 461a3e0fd82Sopenharmony_ci text_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT); 462a3e0fd82Sopenharmony_ci textWidth = widthMaxNoPadding; 463a3e0fd82Sopenharmony_ci text_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); 464a3e0fd82Sopenharmony_ci } 465a3e0fd82Sopenharmony_ci return textWidth; 466a3e0fd82Sopenharmony_ci} 467a3e0fd82Sopenharmony_ci 468a3e0fd82Sopenharmony_ciuint16_t UIDialog::MeasureButtonWidth() 469a3e0fd82Sopenharmony_ci{ 470a3e0fd82Sopenharmony_ci if (buttonNum_ == 0) { 471a3e0fd82Sopenharmony_ci return 0; 472a3e0fd82Sopenharmony_ci } 473a3e0fd82Sopenharmony_ci 474a3e0fd82Sopenharmony_ci uint16_t buttonTextWidth = 0; 475a3e0fd82Sopenharmony_ci // 2: there are 2 paddings horizontally 476a3e0fd82Sopenharmony_ci uint16_t buttonMaxWidth = (widthMax_ - 2 * BUTTON_PADDING - (buttonNum_ - 1) * BUTTON_MID_PADDING) / buttonNum_; 477a3e0fd82Sopenharmony_ci 478a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 479a3e0fd82Sopenharmony_ci const char* text1 = button1_->GetText(); 480a3e0fd82Sopenharmony_ci buttonTextWidth = 481a3e0fd82Sopenharmony_ci MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text1, button1_->GetFontId(), BUTTON_FONT_SIZE, 482a3e0fd82Sopenharmony_ci button1_->GetStyleConst().letterSpace_, 483a3e0fd82Sopenharmony_ci button1_->GetStyleConst().lineHeight_, widthMax_, 0).x); 484a3e0fd82Sopenharmony_ci } 485a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 486a3e0fd82Sopenharmony_ci const char* text2 = button2_->GetText(); 487a3e0fd82Sopenharmony_ci buttonTextWidth = 488a3e0fd82Sopenharmony_ci MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text2, button2_->GetFontId(), BUTTON_FONT_SIZE, 489a3e0fd82Sopenharmony_ci button2_->GetStyleConst().letterSpace_, 490a3e0fd82Sopenharmony_ci button2_->GetStyleConst().lineHeight_, widthMax_, 0).x); 491a3e0fd82Sopenharmony_ci } 492a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 493a3e0fd82Sopenharmony_ci const char* text3 = button3_->GetText(); 494a3e0fd82Sopenharmony_ci buttonTextWidth = 495a3e0fd82Sopenharmony_ci MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text3, button3_->GetFontId(), BUTTON_FONT_SIZE, 496a3e0fd82Sopenharmony_ci button3_->GetStyleConst().letterSpace_, 497a3e0fd82Sopenharmony_ci button3_->GetStyleConst().lineHeight_, widthMax_, 0).x); 498a3e0fd82Sopenharmony_ci } 499a3e0fd82Sopenharmony_ci return (buttonTextWidth + BUTTON_HEIGHT) > buttonMaxWidth ? buttonMaxWidth : (buttonTextWidth + BUTTON_HEIGHT); 500a3e0fd82Sopenharmony_ci} 501a3e0fd82Sopenharmony_ci 502a3e0fd82Sopenharmony_civoid UIDialog::Layout() 503a3e0fd82Sopenharmony_ci{ 504a3e0fd82Sopenharmony_ci if (title_ != nullptr) { 505a3e0fd82Sopenharmony_ci // 2: there are 2 paddings vertically 506a3e0fd82Sopenharmony_ci uint8_t padding = (TITLE_TOTAL_HEIGHT - title_->GetHeight()) / 2; 507a3e0fd82Sopenharmony_ci title_->LayoutLeftOfParent(PADDING); 508a3e0fd82Sopenharmony_ci title_->LayoutTopOfParent(padding); 509a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 510a3e0fd82Sopenharmony_ci text_->LayoutLeftOfParent(PADDING); 511a3e0fd82Sopenharmony_ci text_->LayoutBottomToSibling(TITLE_ID, padding); 512a3e0fd82Sopenharmony_ci } 513a3e0fd82Sopenharmony_ci } else { 514a3e0fd82Sopenharmony_ci if (text_ != nullptr) { 515a3e0fd82Sopenharmony_ci text_->LayoutLeftOfParent(PADDING); 516a3e0fd82Sopenharmony_ci text_->LayoutTopOfParent(PADDING); 517a3e0fd82Sopenharmony_ci } 518a3e0fd82Sopenharmony_ci } 519a3e0fd82Sopenharmony_ci LayoutButton(); 520a3e0fd82Sopenharmony_ci} 521a3e0fd82Sopenharmony_ci 522a3e0fd82Sopenharmony_civoid UIDialog::LayoutButton() 523a3e0fd82Sopenharmony_ci{ 524a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 525a3e0fd82Sopenharmony_ci button1_->LayoutLeftOfParent(BUTTON_PADDING); 526a3e0fd82Sopenharmony_ci button1_->LayoutBottomOfParent(BUTTON_PADDING); 527a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 528a3e0fd82Sopenharmony_ci button2_->LayoutRightToSibling(BUTTON1_ID, BUTTON_MID_PADDING); 529a3e0fd82Sopenharmony_ci button2_->LayoutBottomOfParent(BUTTON_PADDING); 530a3e0fd82Sopenharmony_ci } 531a3e0fd82Sopenharmony_ci } else if (button2_ != nullptr) { 532a3e0fd82Sopenharmony_ci button2_->LayoutLeftOfParent(BUTTON_PADDING); 533a3e0fd82Sopenharmony_ci button2_->LayoutBottomOfParent(BUTTON_PADDING); 534a3e0fd82Sopenharmony_ci } 535a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 536a3e0fd82Sopenharmony_ci button3_->LayoutRightOfParent(BUTTON_PADDING); 537a3e0fd82Sopenharmony_ci button3_->LayoutBottomOfParent(BUTTON_PADDING); 538a3e0fd82Sopenharmony_ci } 539a3e0fd82Sopenharmony_ci 540a3e0fd82Sopenharmony_ci if (buttonNum_ == 3) { // 3: three buttons 541a3e0fd82Sopenharmony_ci line1_->LayoutBottomOfParent(LINE_BOTTOM_PADDING); 542a3e0fd82Sopenharmony_ci line1_->LayoutRightToSibling(BUTTON1_ID, LINE_BUTTON_PADDING); 543a3e0fd82Sopenharmony_ci line2_->LayoutBottomOfParent(LINE_BOTTOM_PADDING); 544a3e0fd82Sopenharmony_ci line2_->LayoutRightToSibling(BUTTON2_ID, LINE_BUTTON_PADDING); 545a3e0fd82Sopenharmony_ci } else if (buttonNum_ == 2) { // 2: two buttons 546a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 547a3e0fd82Sopenharmony_ci line1_->LayoutBottomOfParent(LINE_BOTTOM_PADDING); 548a3e0fd82Sopenharmony_ci line1_->LayoutRightToSibling(BUTTON1_ID, LINE_BUTTON_PADDING); 549a3e0fd82Sopenharmony_ci } else { 550a3e0fd82Sopenharmony_ci line1_->LayoutBottomOfParent(LINE_BOTTOM_PADDING); 551a3e0fd82Sopenharmony_ci line1_->LayoutRightToSibling(BUTTON2_ID, LINE_BUTTON_PADDING); 552a3e0fd82Sopenharmony_ci } 553a3e0fd82Sopenharmony_ci } 554a3e0fd82Sopenharmony_ci} 555a3e0fd82Sopenharmony_ci 556a3e0fd82Sopenharmony_civoid UIDialog::CreateDialogWindow() 557a3e0fd82Sopenharmony_ci{ 558a3e0fd82Sopenharmony_ci dialogLayer_->LayoutCenterOfParent(); 559a3e0fd82Sopenharmony_ci Rect rect = dialogLayer_->GetRect(); 560a3e0fd82Sopenharmony_ci int16_t offset_x = dialogLayer_->GetX(); 561a3e0fd82Sopenharmony_ci int16_t offset_y = dialogLayer_->GetY(); 562a3e0fd82Sopenharmony_ci 563a3e0fd82Sopenharmony_ci windowRootView_->SetPosition(-offset_x, -offset_y); 564a3e0fd82Sopenharmony_ci windowRootView_->Invalidate(); 565a3e0fd82Sopenharmony_ci 566a3e0fd82Sopenharmony_ci WindowConfig config = {}; 567a3e0fd82Sopenharmony_ci config.rect = rect; 568a3e0fd82Sopenharmony_ci config.rect.SetPosition(offset_x, offset_y); 569a3e0fd82Sopenharmony_ci config.isModal = true; 570a3e0fd82Sopenharmony_ci window_ = Window::CreateWindow(config); 571a3e0fd82Sopenharmony_ci if (window_ != nullptr) { 572a3e0fd82Sopenharmony_ci window_->BindRootView(windowRootView_); 573a3e0fd82Sopenharmony_ci } else { 574a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("Create window false!"); 575a3e0fd82Sopenharmony_ci } 576a3e0fd82Sopenharmony_ci} 577a3e0fd82Sopenharmony_ci 578a3e0fd82Sopenharmony_civoid UIDialog::SetButtonColor(DialogButtonType buttonType, ColorType color) 579a3e0fd82Sopenharmony_ci{ 580a3e0fd82Sopenharmony_ci switch (buttonType) { 581a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_LEFT: 582a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 583a3e0fd82Sopenharmony_ci button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, color.full, UIButton::ButtonState::RELEASED); 584a3e0fd82Sopenharmony_ci button1_->SetStyleForState(STYLE_BACKGROUND_OPA, color.alpha, UIButton::ButtonState::RELEASED); 585a3e0fd82Sopenharmony_ci colorType1_ = color; 586a3e0fd82Sopenharmony_ci } 587a3e0fd82Sopenharmony_ci break; 588a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_MID: 589a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 590a3e0fd82Sopenharmony_ci button2_->SetStyleForState(STYLE_BACKGROUND_COLOR, color.full, UIButton::ButtonState::RELEASED); 591a3e0fd82Sopenharmony_ci button2_->SetStyleForState(STYLE_BACKGROUND_OPA, color.alpha, UIButton::ButtonState::RELEASED); 592a3e0fd82Sopenharmony_ci colorType2_ = color; 593a3e0fd82Sopenharmony_ci } 594a3e0fd82Sopenharmony_ci break; 595a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_RIGHT: 596a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 597a3e0fd82Sopenharmony_ci button3_->SetStyleForState(STYLE_BACKGROUND_COLOR, color.full, UIButton::ButtonState::RELEASED); 598a3e0fd82Sopenharmony_ci button3_->SetStyleForState(STYLE_BACKGROUND_COLOR, color.alpha, UIButton::ButtonState::RELEASED); 599a3e0fd82Sopenharmony_ci colorType3_ = color; 600a3e0fd82Sopenharmony_ci } 601a3e0fd82Sopenharmony_ci break; 602a3e0fd82Sopenharmony_ci default: 603a3e0fd82Sopenharmony_ci break; 604a3e0fd82Sopenharmony_ci } 605a3e0fd82Sopenharmony_ci} 606a3e0fd82Sopenharmony_ci 607a3e0fd82Sopenharmony_civoid UIDialog::SetOnCancelListener(UIView::OnClickListener* onCancelListener) 608a3e0fd82Sopenharmony_ci{ 609a3e0fd82Sopenharmony_ci if (onCancelListener == nullptr) { 610a3e0fd82Sopenharmony_ci return; 611a3e0fd82Sopenharmony_ci } 612a3e0fd82Sopenharmony_ci onCancelListener_ = onCancelListener; 613a3e0fd82Sopenharmony_ci} 614a3e0fd82Sopenharmony_ci 615a3e0fd82Sopenharmony_civoid UIDialog::EnableAutoCancel(bool enable) 616a3e0fd82Sopenharmony_ci{ 617a3e0fd82Sopenharmony_ci enableAutoCancel_ = enable; 618a3e0fd82Sopenharmony_ci} 619a3e0fd82Sopenharmony_ci 620a3e0fd82Sopenharmony_civoid UIDialog::DestroyWindow() 621a3e0fd82Sopenharmony_ci{ 622a3e0fd82Sopenharmony_ci if (window_ != nullptr) { 623a3e0fd82Sopenharmony_ci Window::DestroyWindow(window_); 624a3e0fd82Sopenharmony_ci window_ = nullptr; 625a3e0fd82Sopenharmony_ci } 626a3e0fd82Sopenharmony_ci} 627a3e0fd82Sopenharmony_ci 628a3e0fd82Sopenharmony_ci#ifdef ENABLE_DEBUG 629a3e0fd82Sopenharmony_ciconst char* UIDialog::GetButtonText(DialogButtonType buttonType) const 630a3e0fd82Sopenharmony_ci{ 631a3e0fd82Sopenharmony_ci switch (buttonType) { 632a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_LEFT: 633a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 634a3e0fd82Sopenharmony_ci return button1_->GetText(); 635a3e0fd82Sopenharmony_ci } 636a3e0fd82Sopenharmony_ci return nullptr; 637a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_MID: 638a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 639a3e0fd82Sopenharmony_ci return button2_->GetText(); 640a3e0fd82Sopenharmony_ci } 641a3e0fd82Sopenharmony_ci return nullptr; 642a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_RIGHT: 643a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 644a3e0fd82Sopenharmony_ci return button3_->GetText(); 645a3e0fd82Sopenharmony_ci } 646a3e0fd82Sopenharmony_ci return nullptr; 647a3e0fd82Sopenharmony_ci default: 648a3e0fd82Sopenharmony_ci return nullptr; 649a3e0fd82Sopenharmony_ci } 650a3e0fd82Sopenharmony_ci} 651a3e0fd82Sopenharmony_ci 652a3e0fd82Sopenharmony_ciUIView::OnClickListener* UIDialog::GetButtonListener(DialogButtonType buttonType) const 653a3e0fd82Sopenharmony_ci{ 654a3e0fd82Sopenharmony_ci switch (buttonType) { 655a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_LEFT: 656a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 657a3e0fd82Sopenharmony_ci return button1_->GetOnClickListener(); 658a3e0fd82Sopenharmony_ci } 659a3e0fd82Sopenharmony_ci return nullptr; 660a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_MID: 661a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 662a3e0fd82Sopenharmony_ci return button2_->GetOnClickListener(); 663a3e0fd82Sopenharmony_ci } 664a3e0fd82Sopenharmony_ci return nullptr; 665a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_RIGHT: 666a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 667a3e0fd82Sopenharmony_ci return button3_->GetOnClickListener(); 668a3e0fd82Sopenharmony_ci } 669a3e0fd82Sopenharmony_ci return nullptr; 670a3e0fd82Sopenharmony_ci default: 671a3e0fd82Sopenharmony_ci return nullptr; 672a3e0fd82Sopenharmony_ci } 673a3e0fd82Sopenharmony_ci} 674a3e0fd82Sopenharmony_ci 675a3e0fd82Sopenharmony_ciColorType UIDialog::GetButtonColor(DialogButtonType buttonType) const 676a3e0fd82Sopenharmony_ci{ 677a3e0fd82Sopenharmony_ci switch (buttonType) { 678a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_LEFT: 679a3e0fd82Sopenharmony_ci if (button1_ != nullptr) { 680a3e0fd82Sopenharmony_ci return colorType1_; 681a3e0fd82Sopenharmony_ci } 682a3e0fd82Sopenharmony_ci break; 683a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_MID: 684a3e0fd82Sopenharmony_ci if (button2_ != nullptr) { 685a3e0fd82Sopenharmony_ci return colorType2_; 686a3e0fd82Sopenharmony_ci } 687a3e0fd82Sopenharmony_ci break; 688a3e0fd82Sopenharmony_ci case DialogButtonType::BUTTON_RIGHT: 689a3e0fd82Sopenharmony_ci if (button3_ != nullptr) { 690a3e0fd82Sopenharmony_ci return colorType3_; 691a3e0fd82Sopenharmony_ci } 692a3e0fd82Sopenharmony_ci break; 693a3e0fd82Sopenharmony_ci default: 694a3e0fd82Sopenharmony_ci break; 695a3e0fd82Sopenharmony_ci } 696a3e0fd82Sopenharmony_ci ASSERT(0); 697a3e0fd82Sopenharmony_ci} 698a3e0fd82Sopenharmony_ci#endif // ENABLE_DEBUG 699a3e0fd82Sopenharmony_ci} // namespace OHOS 700a3e0fd82Sopenharmony_ci#endif // ENABLE_WINDOW 701