tb_message_window.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_OK,
  12. TB_MSG_OK_CANCEL,
  13. TB_MSG_YES_NO
  14. };
  15. /** TBMessageWindowSettings contains additional settings for TBMessageWindow. */
  16. class TBMessageWindowSettings
  17. {
  18. public:
  19. TBMessageWindowSettings() : msg(TB_MSG_OK), dimmer(false), styling(false) {}
  20. TBMessageWindowSettings(TB_MSG msg, TBID icon_skin) : msg(msg), icon_skin(icon_skin), dimmer(false), styling(false) {}
  21. public:
  22. TB_MSG msg; ///< The type of response for the message.
  23. TBID icon_skin; ///< The icon skin (0 for no icon)
  24. bool dimmer; ///< Set to true to dim background widgets by a TBDimmer.
  25. bool styling; ///< Enable styling in the textfield.
  26. };
  27. /** TBMessageWindow is a window for showing simple messages.
  28. Events invoked in this window will travel up through the target widget.
  29. When the user click any of its buttons, it will invoke a click event
  30. (with the window ID), with the clicked buttons id as ref_id.
  31. Then it will delete itself.
  32. If the target widget is deleted while this window is alive, the
  33. window will delete itself. */
  34. class TBMessageWindow : public TBWindow, private TBWidgetListener
  35. {
  36. public:
  37. // For safe typecasting
  38. TBOBJECT_SUBCLASS(TBMessageWindow, TBWindow);
  39. TBMessageWindow(TBWidget *target, TBID id);
  40. virtual ~TBMessageWindow();
  41. bool Show(const char *title, const char *message, TBMessageWindowSettings *settings = nullptr, int width = 0, int height = 0);
  42. virtual TBWidget *GetEventDestination() { return m_target.Get(); }
  43. virtual bool OnEvent(const TBWidgetEvent &ev);
  44. virtual void OnDie();
  45. private:
  46. void AddButton(TBID id, bool focused);
  47. // TBWidgetListener
  48. virtual void OnWidgetDelete(TBWidget *widget);
  49. virtual bool OnWidgetDying(TBWidget *widget);
  50. TBWidgetSafePointer m_dimmer;
  51. TBWidgetSafePointer m_target;
  52. };
  53. }; // namespace tb
  54. #endif // TB_MESSAGE_WINDOW_H