MessageBox.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGUI/Dialog.h>
  8. namespace GUI {
  9. class MessageBox : public Dialog {
  10. C_OBJECT(MessageBox)
  11. public:
  12. enum class Type {
  13. None,
  14. Information,
  15. Warning,
  16. Error,
  17. Question
  18. };
  19. enum class InputType {
  20. OK,
  21. OKCancel,
  22. YesNo,
  23. YesNoCancel,
  24. };
  25. virtual ~MessageBox() override;
  26. static int show(Window* parent_window, const StringView& text, const StringView& title, Type type = Type::None, InputType input_type = InputType::OK);
  27. static int show_error(Window* parent_window, const StringView& text);
  28. private:
  29. explicit MessageBox(Window* parent_window, const StringView& text, const StringView& title, Type type = Type::None, InputType input_type = InputType::OK);
  30. bool should_include_ok_button() const;
  31. bool should_include_cancel_button() const;
  32. bool should_include_yes_button() const;
  33. bool should_include_no_button() const;
  34. void build();
  35. RefPtr<Gfx::Bitmap> icon() const;
  36. String m_text;
  37. Type m_type { Type::None };
  38. InputType m_input_type { InputType::OK };
  39. };
  40. }