bannerwindow.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/bannerwindow.h
  3. // Purpose: wxBannerWindow class declaration
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-08-16
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_BANNERWINDOW_H_
  10. #define _WX_BANNERWINDOW_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_BANNERWINDOW
  13. #include "wx/bitmap.h"
  14. #include "wx/event.h"
  15. #include "wx/window.h"
  16. class WXDLLIMPEXP_FWD_CORE wxBitmap;
  17. class WXDLLIMPEXP_FWD_CORE wxColour;
  18. class WXDLLIMPEXP_FWD_CORE wxDC;
  19. extern WXDLLIMPEXP_DATA_ADV(const char) wxBannerWindowNameStr[];
  20. // ----------------------------------------------------------------------------
  21. // A simple banner window showing either a bitmap or text.
  22. // ----------------------------------------------------------------------------
  23. class WXDLLIMPEXP_ADV wxBannerWindow : public wxWindow
  24. {
  25. public:
  26. // Default constructor, use Create() later.
  27. wxBannerWindow() { Init(); }
  28. // Convenient constructor that should be used in the majority of cases.
  29. //
  30. // The banner orientation changes how the text in it is displayed and also
  31. // defines where is the bitmap truncated if it's too big to fit but doesn't
  32. // do anything for the banner position, this is supposed to be taken care
  33. // of in the usual way, e.g. using sizers.
  34. wxBannerWindow(wxWindow* parent, wxDirection dir = wxLEFT)
  35. {
  36. Init();
  37. Create(parent, wxID_ANY, dir);
  38. }
  39. // Full constructor provided for consistency with the other classes only.
  40. wxBannerWindow(wxWindow* parent,
  41. wxWindowID winid,
  42. wxDirection dir = wxLEFT,
  43. const wxPoint& pos = wxDefaultPosition,
  44. const wxSize& size = wxDefaultSize,
  45. long style = 0,
  46. const wxString& name = wxBannerWindowNameStr)
  47. {
  48. Init();
  49. Create(parent, winid, dir, pos, size, style, name);
  50. }
  51. // Can be only called on objects created with the default constructor.
  52. bool Create(wxWindow* parent,
  53. wxWindowID winid,
  54. wxDirection dir = wxLEFT,
  55. const wxPoint& pos = wxDefaultPosition,
  56. const wxSize& size = wxDefaultSize,
  57. long style = 0,
  58. const wxString& name = wxBannerWindowNameStr);
  59. // Provide an existing bitmap to show. For wxLEFT orientation the bitmap is
  60. // truncated from the top, for wxTOP and wxBOTTOM -- from the right and for
  61. // wxRIGHT -- from the bottom, so put the most important part of the bitmap
  62. // information in the opposite direction.
  63. void SetBitmap(const wxBitmap& bmp);
  64. // Set the text to display. This is mutually exclusive with SetBitmap().
  65. // Title is rendered in bold and should be single line, message can have
  66. // multiple lines but is not wrapped automatically.
  67. void SetText(const wxString& title, const wxString& message);
  68. // Set the colours between which the gradient runs. This can be combined
  69. // with SetText() but not SetBitmap().
  70. void SetGradient(const wxColour& start, const wxColour& end);
  71. protected:
  72. virtual wxSize DoGetBestClientSize() const;
  73. private:
  74. // Common part of all constructors.
  75. void Init();
  76. // Fully invalidates the window.
  77. void OnSize(wxSizeEvent& event);
  78. // Redraws the window using either m_bitmap or m_title/m_message.
  79. void OnPaint(wxPaintEvent& event);
  80. // Helper of OnPaint(): draw the bitmap at the correct position depending
  81. // on our orientation.
  82. void DrawBitmapBackground(wxDC& dc);
  83. // Helper of OnPaint(): draw the text in the appropriate direction.
  84. void DrawBannerTextLine(wxDC& dc, const wxString& str, const wxPoint& pos);
  85. // Return the font to use for the title. Currently this is hardcoded as a
  86. // larger bold version of the standard window font but could be made
  87. // configurable in the future.
  88. wxFont GetTitleFont() const;
  89. // Return the colour to use for extending the bitmap. Non-const as it
  90. // updates m_colBitmapBg if needed.
  91. wxColour GetBitmapBg();
  92. // The window side along which the banner is laid out.
  93. wxDirection m_direction;
  94. // If valid, this bitmap is drawn as is.
  95. wxBitmap m_bitmap;
  96. // If bitmap is valid, this is the colour we use to extend it if the bitmap
  97. // is smaller than this window. It is computed on demand by GetBitmapBg().
  98. wxColour m_colBitmapBg;
  99. // The title and main message to draw, used if m_bitmap is invalid.
  100. wxString m_title,
  101. m_message;
  102. // Start and stop gradient colours, only used when drawing text.
  103. wxColour m_colStart,
  104. m_colEnd;
  105. wxDECLARE_EVENT_TABLE();
  106. wxDECLARE_NO_COPY_CLASS(wxBannerWindow);
  107. };
  108. #endif // wxUSE_BANNERWINDOW
  109. #endif // _WX_BANNERWINDOW_H_