tb_message_window.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_MESSAGE_WINDOW_H
  6. #define TB_MESSAGE_WINDOW_H
  7. #include "tb_window.h"
  8. #include "tb_widgets_listener.h"
  9. namespace tb {
  10. enum TB_MSG {
  11. TB_MSG_NONE,
  12. TB_MSG_OK,
  13. TB_MSG_OK_CANCEL,
  14. TB_MSG_YES_NO
  15. };
  16. /** TBMessageWindowSettings contains additional settings for TBMessageWindow. */
  17. class TBMessageWindowSettings
  18. {
  19. public:
  20. TBMessageWindowSettings() : msg(TB_MSG_OK), dimmer(false), styling(false) {}
  21. TBMessageWindowSettings(TB_MSG msg, TBID icon_skin) : msg(msg), icon_skin(icon_skin), dimmer(false), styling(false) {}
  22. public:
  23. TB_MSG msg; ///< The type of response for the message.
  24. TBID icon_skin; ///< The icon skin (0 for no icon)
  25. bool dimmer; ///< Set to true to dim background widgets by a TBDimmer.
  26. bool styling; ///< Enable styling in the textfield.
  27. };
  28. /** TBMessageWindow is a window for showing simple messages.
  29. Events invoked in this window will travel up through the target widget.
  30. When the user click any of its buttons, it will invoke a click event
  31. (with the window ID), with the clicked buttons id as ref_id.
  32. Then it will delete itself.
  33. If the target widget is deleted while this window is alive, the
  34. window will delete itself. */
  35. class TBMessageWindow : public TBWindow, private TBWidgetListener
  36. {
  37. public:
  38. // For safe typecasting
  39. TBOBJECT_SUBCLASS(TBMessageWindow, TBWindow);
  40. TBMessageWindow(TBWidget *target, TBID id);
  41. virtual ~TBMessageWindow();
  42. bool Show(const char *title, const char *message, TBMessageWindowSettings *settings = nullptr, int width = 0, int height = 0);
  43. virtual TBWidget *GetEventDestination() { return m_target.Get(); }
  44. virtual bool OnEvent(const TBWidgetEvent &ev);
  45. virtual void OnDie();
  46. void AddButton(TBID id, bool focused, TBLayout *layout = nullptr);
  47. void AddButtonLeft(TBID id, bool focused);
  48. private:
  49. // TBWidgetListener
  50. virtual void OnWidgetDelete(TBWidget *widget);
  51. virtual bool OnWidgetDying(TBWidget *widget);
  52. TBWidgetSafePointer m_dimmer;
  53. TBWidgetSafePointer m_target;
  54. };
  55. }; // namespace tb
  56. #endif // TB_MESSAGE_WINDOW_H