]>
Commit | Line | Data |
---|---|---|
a92b5dfe VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/infobar.h | |
3 | // Purpose: interface of wxInfoBar | |
4 | // Author: Vadim Zeitlin | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org> | |
7 | // Licence: wxWindows license | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | /** | |
11 | An info bar is a transient window shown at top or bottom of its parent | |
12 | window to display non-critical information to the user. | |
13 | ||
14 | This class provides another way to show messages to the user, intermediate | |
15 | between message boxes and status bar messages. The message boxes are modal | |
16 | and thus interrupt the users work flow and should be used sparingly for | |
17 | this reason. However status bar messages are often too easy not to notice | |
18 | at all. An info bar provides a way to present the messages which has a much | |
19 | higher chance to be noticed by the user but without being annoying. | |
20 | ||
21 | Info bar may show an icon (on the left), text message and, optionally, | |
22 | buttons allowing the user to react to the information presented. It always | |
23 | has a close button at the right allowing the user to dismiss it so it isn't | |
24 | necessary to provide a button just to close it. | |
25 | ||
26 | wxInfoBar calls its parent wxWindow::Layout() method and assumes that it | |
27 | will change the parent layout appropriately depending on whether the info | |
28 | bar itself is shown or hidden. Usually this is achieved by simply using a | |
29 | sizer for the parent window layout and adding wxInfoBar to this sizer as | |
30 | one of the items. Considering the usual placement of the info bars, | |
31 | normally this sizer should be a vertical wxBoxSizer and the bar its first | |
32 | or last element so the simplest possible example of using this class would | |
33 | be: | |
34 | @code | |
35 | class MyFrame : public wxFrame | |
36 | { | |
37 | ... | |
38 | ||
39 | wxInfoBar *m_infoBar; | |
40 | }; | |
41 | ||
42 | MyFrame::MyFrame() | |
43 | { | |
44 | ... | |
45 | m_infoBar = new wxInfoBar(this); | |
46 | ||
47 | wxSizer *sizer = new wxBoxSizer(wxVERTICAL); | |
48 | sizer->Add(m_infoBar, wxSizerFlags().Expand()); | |
49 | ... add other frame controls to the sizer ... | |
50 | SetSizer(sizer); | |
51 | } | |
52 | ||
53 | void MyFrame::SomeMethod() | |
54 | { | |
55 | m_infoBar->ShowMessage("Something happend", wxICON_INFORMATION); | |
56 | } | |
57 | @endcode | |
58 | ||
59 | See the dialogs sample for more sophisticated examples. | |
60 | ||
61 | ||
ed8efd46 VZ |
62 | Currently this class is implemented generically (i.e. in the same |
63 | platform-independent way for all ports) and also natively in wxGTK but the | |
64 | native implementation requires a recent -- as of this writing -- GTK+ 2.18 | |
65 | version. | |
a92b5dfe VZ |
66 | |
67 | @library{wxadv} | |
68 | @category{miscwnd} | |
69 | ||
70 | @see wxStatusBar, wxMessageDialog | |
71 | ||
72 | @since 2.9.1 | |
73 | */ | |
3996b21a | 74 | class wxInfoBar : public wxControl |
a92b5dfe VZ |
75 | { |
76 | public: | |
77 | /** | |
78 | Default constructor. | |
79 | ||
80 | Use Create() for the objects created using this constructor. | |
81 | */ | |
82 | wxInfoBar(); | |
83 | ||
84 | /** | |
85 | Constructor creating the info bar window. | |
86 | ||
87 | @see Create() | |
88 | */ | |
89 | wxInfoBar(wxWindow *parent, wxWindowID winid = wxID_ANY); | |
90 | ||
91 | /** | |
92 | Create the info bar window. | |
93 | ||
94 | Notice that unlike most of the other wxWindow-derived classes, | |
95 | wxInfoBar is created hidden and is only shown when ShowMessage() is | |
96 | called. This is more convenient as usually the info bar is created to | |
97 | be shown at some later time and not immediately and so creating it | |
98 | hidden avoids the need to call Hide() explicitly from the code using | |
99 | it. | |
100 | ||
101 | This should be only called if the object was created using its default | |
102 | constructor. | |
103 | ||
104 | @param parent | |
105 | A valid parent window pointer. | |
106 | @param winid | |
107 | The id of the info bar window, usually unused as currently no | |
108 | events are generated by this class. | |
109 | */ | |
110 | wxInfoBar(wxWindow *parent, wxWindowID winid = wxID_ANY); | |
111 | ||
112 | /** | |
113 | Add a button to be shown in the info bar. | |
114 | ||
115 | The button added by this method will be shown to the right of the text | |
116 | (in LTR layout), with each successive button being added to the right | |
6a3f8b4f VZ |
117 | of the previous one. If any buttons are added to the info bar using |
118 | this method, the default "Close" button is not shown as it is assumed | |
119 | that the extra buttons already allow the user to close it. | |
a92b5dfe | 120 | |
c0945eb2 VZ |
121 | Clicking the button will generate a normal EVT_COMMAND_BUTTON_CLICKED |
122 | event which can be handled as usual. The default handler in wxInfoBar | |
123 | itself closes the window whenever a button in it is clicked so if you | |
124 | wish the info bar to be hidden when the button is clicked, simply call | |
125 | @c event.Skip() in the button handler to let the base class handler do | |
0b1add25 VZ |
126 | it (calling Dismiss() explicitly works too, of course). On the other |
127 | hand, if you don't skip the event, the info bar will remain opened so | |
128 | make sure to do it for at least some buttons to allow the user to close | |
129 | it. | |
c0945eb2 VZ |
130 | |
131 | Notice that the generic wxInfoBar implementation handles the button | |
132 | events itself and so they are not propagated to the info bar parent and | |
133 | you need to either inherit from wxInfoBar and handle them in your | |
134 | derived class or use wxEvtHandler::Connect(), as is done in the dialogs | |
135 | sample, to handle the button events in the parent frame. | |
a92b5dfe VZ |
136 | |
137 | @param btnid | |
138 | Id of the button. It will be used in the button message clicking | |
139 | this button will generate. | |
140 | @param label | |
141 | The label of the button. It may only be empty if @a btnid is one of | |
142 | the stock ids in which case the corresponding stock label (see | |
143 | wxGetStockLabel()) will be used. | |
144 | */ | |
145 | void AddButton(wxWindowID btnid, const wxString& label = wxString()); | |
146 | ||
0b1add25 VZ |
147 | /** |
148 | Hide the info bar window. | |
149 | ||
150 | This method hides the window and lays out the parent window to account | |
151 | for its disappearance (unlike a simple Hide()). | |
152 | */ | |
153 | void Dismiss(); | |
154 | ||
e6b2aae1 VZ |
155 | /** |
156 | Remove a button previously added by AddButton(). | |
157 | ||
158 | @param btnid | |
159 | Id of the button to remove. If more than one button with the same | |
160 | id is used in the info bar (which is in any case not recommended), | |
161 | the last, i.e. most recently added, button with this id is removed. | |
162 | */ | |
163 | void RemoveButton(wxWindowID btnid); | |
164 | ||
a92b5dfe VZ |
165 | /** |
166 | Show a message in the bar. | |
167 | ||
168 | If the bar is currently hidden, it will be shown. Otherwise its message | |
169 | will be updated in place. | |
170 | ||
171 | @param msg | |
172 | The text of the message. | |
173 | @param flags | |
ed8efd46 | 174 | One of wxICON_NONE, wxICON_INFORMATION (default), wxICON_QUESTION, |
a92b5dfe | 175 | wxICON_WARNING or wxICON_ERROR values. These flags have the same |
ed8efd46 VZ |
176 | meaning as in wxMessageDialog for the generic version, i.e. show |
177 | (or not, in case of wxICON_NONE) the corresponding icon in the bar | |
178 | but can be interpreted by the native versions. For example, the | |
179 | GTK+ native implementation doesn't show icons at all but uses this | |
180 | parameter to select the appropriate background colour for the | |
181 | notification. | |
a92b5dfe VZ |
182 | */ |
183 | void ShowMessage(const wxString& msg, int flags = wxICON_NONE); | |
184 | ||
185 | /** | |
186 | @name Generic version customization methods. | |
187 | ||
188 | All these methods exist in the generic version of the class only. | |
189 | ||
190 | The generic version uses wxWindow::ShowWithEffect() function to | |
ed8efd46 VZ |
191 | progressively show it on the platforms which support it (currently only |
192 | wxMSW). The methods here allow to change the default effect used (or | |
193 | disable it entirely) and change its duration. | |
a92b5dfe VZ |
194 | */ |
195 | //@{ | |
196 | ||
197 | /** | |
198 | Set the effects to use when showing and hiding the bar. | |
199 | ||
200 | Either or both of the parameters can be set to wxSHOW_EFFECT_NONE to | |
201 | disable using effects entirely. | |
202 | ||
3996b21a VZ |
203 | By default, the info bar uses wxSHOW_EFFECT_SLIDE_TO_BOTTOM effect for |
204 | showing itself and wxSHOW_EFFECT_SLIDE_TO_TOP for hiding if it is the | |
205 | first element of the containing sizer and reverse effects if it's the | |
206 | last one. If it is neither the first nor the last element, no effect is | |
207 | used to avoid the use of an inappropriate one and this function must be | |
208 | called if an effect is desired. | |
a92b5dfe VZ |
209 | |
210 | @param showEffect | |
3996b21a | 211 | The effect to use when showing the bar. |
a92b5dfe | 212 | @param hideEffect |
3996b21a | 213 | The effect to use when hiding the bar. |
a92b5dfe VZ |
214 | */ |
215 | void SetShowHideEffects(wxShowEffect showEffect, wxShowEffect hideEffect); | |
216 | ||
217 | /// Return the effect currently used for showing the bar. | |
218 | wxShowEffect GetShowEffect() const; | |
219 | ||
220 | /// Return the effect currently used for hiding the bar. | |
221 | wxShowEffect GetHideEffect() const; | |
222 | ||
223 | /** | |
224 | Set the duration of the animation used when showing or hiding the bar. | |
225 | ||
226 | By default, 500ms duration is used. | |
227 | ||
228 | @param duration | |
229 | Duration of the animation, in milliseconds. | |
230 | */ | |
231 | void SetEffectDuration(int duration); | |
232 | ||
233 | /// Return the effect animation duration currently used. | |
234 | int GetEffectDuration() const; | |
235 | ||
236 | /** | |
237 | Overridden base class methods changes the font of the text message. | |
238 | ||
239 | wxInfoBar overrides this method to use the font passed to it for its | |
240 | text message part. By default a larger and bold version of the standard | |
241 | font is used. | |
242 | ||
243 | This method is generic-only. | |
244 | */ | |
245 | virtual bool SetFont(const wxFont& font); | |
246 | ||
247 | //@} | |
248 | }; |