MessageBox.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Copyright (c) 2008-2014 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 "Object.h"
  24. namespace Urho3D
  25. {
  26. class Button;
  27. class Text;
  28. class UIElement;
  29. class XMLFile;
  30. /// Message box dialog.
  31. class URHO3D_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, XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
  37. /// Destruct.
  38. virtual ~MessageBox();
  39. /// Register object factory.
  40. static void RegisterObject(Context* context);
  41. /// Set title text. No-ops if there is no title text element.
  42. void SetTitle(const String& text);
  43. /// Set message text. No-ops if there is no message text element.
  44. void SetMessage(const String& text);
  45. /// Return title text. Return empty string if there is no title text element.
  46. const String& GetTitle() const;
  47. /// Return message text. Return empty string if there is no message text element.
  48. const String& GetMessage() const;
  49. /// Return dialog window.
  50. UIElement* GetWindow() const { return window_; }
  51. private:
  52. /// Handle events that dismiss the message box.
  53. void HandleMessageAcknowledged(StringHash eventType, VariantMap& eventData);
  54. /// UI element containing the whole UI layout. Typically it is a Window element type.
  55. SharedPtr<UIElement> window_;
  56. /// Title text element.
  57. Text* titleText_;
  58. /// Message text element.
  59. Text* messageText_;
  60. /// OK button element.
  61. Button* okButton_;
  62. };
  63. }