MessageBox.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Core/Object.h"
  24. namespace Atomic
  25. {
  26. class Button;
  27. class Text;
  28. class UIElement;
  29. class XMLFile;
  30. /// Message box dialog.
  31. class ATOMIC_API MessageBox : public Object
  32. {
  33. OBJECT(MessageBox);
  34. public:
  35. /// 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.
  36. MessageBox(Context* context, const String& messageString = String::EMPTY, const String& titleString = String::EMPTY,
  37. XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
  38. /// Destruct.
  39. virtual ~MessageBox();
  40. /// Register object factory.
  41. static void RegisterObject(Context* context);
  42. /// Set title text. No-ops if there is no title text element.
  43. void SetTitle(const String& text);
  44. /// Set message text. No-ops if there is no message text element.
  45. void SetMessage(const String& text);
  46. /// Return title text. Return empty string if there is no title text element.
  47. const String& GetTitle() const;
  48. /// Return message text. Return empty string if there is no message text element.
  49. const String& GetMessage() const;
  50. /// Return dialog window.
  51. UIElement* GetWindow() const { return window_; }
  52. private:
  53. /// Handle events that dismiss the message box.
  54. void HandleMessageAcknowledged(StringHash eventType, VariantMap& eventData);
  55. /// UI element containing the whole UI layout. Typically it is a Window element type.
  56. SharedPtr<UIElement> window_;
  57. /// Title text element.
  58. Text* titleText_;
  59. /// Message text element.
  60. Text* messageText_;
  61. /// OK button element.
  62. Button* okButton_;
  63. };
  64. }