bannerwindow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: interface/wx/bannerwindow.h
  3. // Purpose: wxBannerWindow class documentation
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-08-16
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. /**
  10. A simple banner window showing either a bitmap or text.
  11. Banner windows can be used to present some overview of the current window
  12. contents to the user in an aesthetically pleasant way. They are typically
  13. positioned along the left or top edge of the window (although this class
  14. also supports right- and bottom-aligned banners) and show either a bitmap
  15. with a logo or a few lines of text on a gradient-filled background.
  16. Using this class is very simple, e.g.:
  17. @code
  18. MyFrame::MyFrame(...)
  19. {
  20. ... create the frame itself ...
  21. // Create and initialize the banner.
  22. wxBannerWindow* banner = new wxBannerWindow(this, wxTOP);
  23. banner->SetText("Welcome to my wonderful program",
  24. " Before doing anything else, you need to connect to "
  25. "the online server.\n"
  26. " Please enter your credentials in the controls below.");
  27. // And position it along the left edge of the window.
  28. wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
  29. sizer->Add(banner, wxSizerFlags().Expand());
  30. ... add the rest of the window contents to the same sizer ...
  31. SetSizerAndFit(sizer);
  32. }
  33. @endcode
  34. This class is currently implemented generically and so looks the same under
  35. all platforms.
  36. @library{wxadv}
  37. @category{miscwnd}
  38. @genericAppearance{bannerwindow}
  39. @since 2.9.3
  40. */
  41. class wxBannerWindow : public wxWindow
  42. {
  43. public:
  44. /**
  45. Default constructor, use Create() later.
  46. This constructor is only used for two-step creation, if possible,
  47. prefer using the constructor below directly instead of using this one
  48. and calling Create() later.
  49. */
  50. wxBannerWindow();
  51. /**
  52. Convenient constructor that should be used in the majority of cases.
  53. The only really important arguments of the full constructor below are
  54. @a parent and @a dir so this class provides a convenient constructor
  55. taking only them.
  56. The banner orientation changes how the text in it is displayed and also
  57. defines where is the bitmap truncated if it's too big to fit but doesn't
  58. do anything for the banner position, this is supposed to be taken care
  59. of in the usual way, e.g. using sizers.
  60. */
  61. wxBannerWindow(wxWindow* parent, wxDirection dir = wxLEFT);
  62. /**
  63. Full constructor provided for consistency with the other classes only.
  64. Prefer to use the shorter constructor documented above. You should
  65. rarely, if ever, need to use non-default values for any other
  66. parameters: as the banner window doesn't generate any events, its
  67. identifier is not particularly useful; its position and size will be
  68. almost always managed by the containing sizer and it doesn't have any
  69. specific styles. So only the parent and the banner direction need to be
  70. specified.
  71. */
  72. wxBannerWindow(wxWindow* parent,
  73. wxWindowID winid,
  74. wxDirection dir = wxLEFT,
  75. const wxPoint& pos = wxDefaultPosition,
  76. const wxSize& size = wxDefaultSize,
  77. long style = 0,
  78. const wxString& name = wxBannerWindowNameStr);
  79. /**
  80. Really create the banner window for the objects created using the
  81. default constructor.
  82. It's an error to call Create() for the objects created using
  83. non-default constructor.
  84. */
  85. bool Create(wxWindow* parent,
  86. wxWindowID winid,
  87. wxDirection dir = wxLEFT,
  88. const wxPoint& pos = wxDefaultPosition,
  89. const wxSize& size = wxDefaultSize,
  90. long style = 0,
  91. const wxString& name = wxBannerWindowNameStr);
  92. /**
  93. Provide the bitmap to use as background.
  94. Notice that ideally the bitmap should be big enough to always cover the
  95. entire banner, e.g. for a horizontal banner with wxTOP style its width
  96. should be bigger than any reasonable window size. Otherwise the bitmap
  97. is extended to cover the entire window area with a solid colour taken
  98. from the bitmap pixel on the edge in which direction the extension
  99. occurs so all bitmap pixels on this edge (top for wxLEFT, right for
  100. wxTOP and wxBOTTOM and bottom for wxRIGHT) should have the same colour
  101. to avoid jarring discontinuity.
  102. If, on the other hand, the bitmap is bigger than the window size, then
  103. it is truncated. For wxLEFT orientation the bitmap is truncated from
  104. the top, for wxTOP and wxBOTTOM -- from the right and for wxRIGHT --
  105. from the bottom, so put the most important part of the bitmap
  106. information in the opposite direction where it will never be truncated.
  107. If no valid background bitmap is specified, the banner draws gradient
  108. background but if a valid bitmap is given here, the gradient is not
  109. draw and the start and end colours specified for it are ignored.
  110. @param bmp Bitmap to use as background. May be invalid to indicate
  111. that no background bitmap should be used.
  112. */
  113. void SetBitmap(const wxBitmap& bmp);
  114. /**
  115. Set the text to display.
  116. This is mutually exclusive with SetBitmap().
  117. Title is rendered in bold and should be single line, message can have
  118. multiple lines but is not wrapped automatically, include explicit line
  119. breaks in the string if you want to have multiple lines.
  120. */
  121. void SetText(const wxString& title, const wxString& message);
  122. /**
  123. Set the colours between which the gradient runs.
  124. The gradient colours are ignored if SetBitmap() is used.
  125. */
  126. void SetGradient(const wxColour& start, const wxColour& end);
  127. };