MessageBox.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Core/Object.h"
  5. namespace Urho3D
  6. {
  7. class Button;
  8. class Text;
  9. class UIElement;
  10. class XMLFile;
  11. /// Message box dialog. Manages its lifetime automatically, so the application does not need to hold a reference to it, and shouldn't attempt to destroy it manually.
  12. class URHO3D_API MessageBox : public Object
  13. {
  14. URHO3D_OBJECT(MessageBox, Object);
  15. public:
  16. /// Construct. If layout file is not given, use the default message box layout. If style file is not given, use the default style file from root UI element.
  17. explicit MessageBox(Context* context, const String& messageString = String::EMPTY, const String& titleString = String::EMPTY,
  18. XMLFile* layoutFile = nullptr, XMLFile* styleFile = nullptr);
  19. /// Destruct.
  20. ~MessageBox() override;
  21. /// Register object factory.
  22. /// @nobind
  23. static void RegisterObject(Context* context);
  24. /// Set title text. No-ops if there is no title text element.
  25. /// @property
  26. void SetTitle(const String& text);
  27. /// Set message text. No-ops if there is no message text element.
  28. /// @property
  29. void SetMessage(const String& text);
  30. /// Return title text. Return empty string if there is no title text element.
  31. /// @property
  32. const String& GetTitle() const;
  33. /// Return message text. Return empty string if there is no message text element.
  34. /// @property
  35. const String& GetMessage() const;
  36. /// Return dialog window.
  37. /// @property
  38. UIElement* GetWindow() const { return window_; }
  39. private:
  40. /// Handle events that dismiss the message box.
  41. void HandleMessageAcknowledged(StringHash eventType, VariantMap& eventData);
  42. /// UI element containing the whole UI layout. Typically it is a Window element type.
  43. UIElement* window_;
  44. /// Title text element.
  45. Text* titleText_;
  46. /// Message text element.
  47. Text* messageText_;
  48. /// OK button element.
  49. Button* okButton_;
  50. };
  51. }