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