1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        statusbr.h
3 // Purpose:     interface of wxStatusBar
4 // Author:      wxWidgets team
5 // Licence:     wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
7 
8 // wxStatusBar styles
9 #define wxSTB_SIZEGRIP         0x0010
10 #define wxSTB_SHOW_TIPS        0x0020
11 
12 #define wxSTB_ELLIPSIZE_START   0x0040
13 #define wxSTB_ELLIPSIZE_MIDDLE  0x0080
14 #define wxSTB_ELLIPSIZE_END     0x0100
15 
16 #define wxSTB_DEFAULT_STYLE    (wxSTB_SIZEGRIP|wxSTB_ELLIPSIZE_END|wxSTB_SHOW_TIPS|wxFULL_REPAINT_ON_RESIZE)
17 
18 // style flags for wxStatusBar fields
19 #define wxSB_NORMAL    0x0000
20 #define wxSB_FLAT      0x0001
21 #define wxSB_RAISED    0x0002
22 #define wxSB_SUNKEN    0x0003
23 
24 
25 /**
26     @class wxStatusBarPane
27 
28     A status bar pane data container used by wxStatusBar.
29 
30     @library{wxcore}
31     @category{data}
32 
33     @see wxStatusBar
34 */
35 class wxStatusBarPane
36 {
37 public:
38     /**
39         Constructs the pane with the given @a style and @a width.
40     */
41     wxStatusBarPane(int style = wxSB_NORMAL, int width = 0);
42 
43     /**
44         Returns the pane width; it maybe negative, indicating a variable-width field.
45     */
46     int GetWidth() const;
47 
48     /**
49         Returns the pane style.
50     */
51     int GetStyle() const;
52 
53     /**
54         Returns the text currently shown in this pane.
55      */
56     wxString GetText() const;
57 };
58 
59 /**
60     @class wxStatusBar
61 
62     A status bar is a narrow window that can be placed along the bottom of a frame
63     to give small amounts of status information. It can contain one or more fields,
64     one or more of which can be variable length according to the size of the window.
65 
66     wxStatusBar also maintains an independent stack of status texts for each field
67     (see PushStatusText() and PopStatusText()).
68 
69     Note that in wxStatusBar context, the terms @e pane and @e field are synonyms.
70 
71     @beginStyleTable
72     @style{wxSTB_SIZEGRIP}
73         Displays a gripper at the right-hand side of the status bar which can be used
74         to resize the parent window.
75     @style{wxSTB_SHOW_TIPS}
76         Displays tooltips for those panes whose status text has been ellipsized/truncated
77         because the status text doesn't fit the pane width.
78         Note that this style has effect only on wxGTK (with GTK+ >= 2.12) currently.
79     @style{wxSTB_ELLIPSIZE_START}
80         Replace the beginning of the status texts with an ellipsis when the status text
81         widths exceed the status bar pane's widths (uses wxControl::Ellipsize).
82     @style{wxSTB_ELLIPSIZE_MIDDLE}
83         Replace the middle of the status texts with an ellipsis when the status text
84         widths exceed the status bar pane's widths (uses wxControl::Ellipsize).
85     @style{wxSTB_ELLIPSIZE_END}
86         Replace the end of the status texts with an ellipsis when the status text
87         widths exceed the status bar pane's widths (uses wxControl::Ellipsize).
88     @style{wxSTB_DEFAULT_STYLE}
89         The default style: includes
90         @c wxSTB_SIZEGRIP|wxSTB_SHOW_TIPS|wxSTB_ELLIPSIZE_END|wxFULL_REPAINT_ON_RESIZE.
91     @endStyleTable
92 
93     @remarks
94     It is possible to create controls and other windows on the status bar.
95     Position these windows from an OnSize() event handler.
96 
97     @remarks
98     Notice that only the first 127 characters of a string will be shown in
99     status bar fields under Windows if a proper manifest indicating that the
100     program uses version 6 of common controls library is not used. This is a
101     limitation of the native control on these platforms.
102 
103     @library{wxcore}
104     @category{miscwnd}
105 
106     @see wxStatusBarPane, wxFrame, @ref page_samples_statbar
107 */
108 class wxStatusBar : public wxControl
109 {
110 public:
111     /**
112         Default ctor.
113     */
114     wxStatusBar();
115 
116     /**
117         Constructor, creating the window.
118 
119         @param parent
120             The window parent, usually a frame.
121         @param id
122             The window identifier.
123             It may take a value of -1 to indicate a default value.
124         @param style
125             The window style. See wxStatusBar.
126         @param name
127             The name of the window. This parameter is used to associate a name with the
128             item, allowing the application user to set Motif resource values for
129             individual windows.
130 
131         @see Create()
132     */
133     wxStatusBar(wxWindow* parent, wxWindowID id = wxID_ANY,
134                 long style = wxSTB_DEFAULT_STYLE,
135                 const wxString& name = wxStatusBarNameStr);
136 
137     /**
138         Destructor.
139     */
140     virtual ~wxStatusBar();
141 
142     /**
143         Creates the window, for two-step construction.
144         See wxStatusBar() for details.
145     */
146     bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
147                 long style = wxSTB_DEFAULT_STYLE,
148                 const wxString& name = wxStatusBarNameStr);
149 
150     /**
151         Returns the size and position of a field's internal bounding rectangle.
152 
153         @param i
154             The field in question.
155         @param rect
156             The rectangle values are placed in this variable.
157 
158         @return @true if the field index is valid, @false otherwise.
159 
160         @beginWxPerlOnly
161         In wxPerl this function returns a @c Wx::Rect if the field
162         index is valid, @c undef otherwise.
163         @endWxPerlOnly
164 
165         @see wxRect
166     */
167     virtual bool GetFieldRect(int i, wxRect& rect) const;
168 
169     /**
170         Returns the number of fields in the status bar.
171     */
172     int GetFieldsCount() const;
173 
174     /**
175         Returns the wxStatusBarPane representing the @a n-th field.
176     */
177     const wxStatusBarPane& GetField(int n) const;
178 
179     /**
180         Returns the horizontal and vertical borders used when rendering the field
181         text inside the field area.
182 
183         Note that the rect returned by GetFieldRect() already accounts for the
184         presence of horizontal and vertical border returned by this function.
185     */
186     wxSize GetBorders() const;
187 
188     /**
189         Returns the string associated with a status bar field.
190 
191         @param i
192             The number of the status field to retrieve, starting from zero.
193 
194         @return The status field string if the field is valid, otherwise the
195                 empty string.
196 
197         @see SetStatusText()
198     */
199     virtual wxString GetStatusText(int i = 0) const;
200 
201     /**
202         Returns the width of the @a n-th field.
203 
204         See wxStatusBarPane::GetWidth() for more info.
205     */
206     int GetStatusWidth(int n) const;
207 
208     /**
209         Returns the style of the @a n-th field.
210 
211         See wxStatusBarPane::GetStyle() for more info.
212     */
213     int GetStatusStyle(int n) const;
214 
215     /**
216         Restores the text to the value it had before the last call to
217         PushStatusText().
218 
219         Notice that if SetStatusText() had been called in the meanwhile,
220         PopStatusText() will not change the text, i.e. it does not override
221         explicit changes to status text but only restores the saved text if it
222         hadn't been changed since.
223 
224         @see PushStatusText()
225     */
226     void PopStatusText(int field = 0);
227 
228     /**
229         Saves the current field text in a per-field stack, and sets the field
230         text to the string passed as argument.
231 
232         @see PopStatusText()
233     */
234     void PushStatusText(const wxString& string, int field = 0);
235 
236     /**
237         Sets the number of fields, and optionally the field widths.
238 
239         @param number
240             The number of fields. If this is greater than the previous number,
241             then new fields with empty strings will be added to the status bar.
242         @param widths
243             An array of n integers interpreted in the same way as
244             in SetStatusWidths().
245 
246         @beginWxPerlOnly
247         In wxPerl this function accepts only the @a number parameter.
248         Use SetStatusWidths to set the field widths.
249         @endWxPerlOnly
250     */
251     virtual void SetFieldsCount(int number = 1, const int* widths = NULL);
252 
253     /**
254         Sets the minimal possible height for the status bar.
255 
256         The real height may be bigger than the height specified here depending
257         on the size of the font used by the status bar.
258     */
259     virtual void SetMinHeight(int height);
260 
261     /**
262         Sets the styles of the fields in the status line which can make fields appear
263         flat or raised instead of the standard sunken 3D border.
264 
265         @param n
266             The number of fields in the status bar. Must be equal to the
267             number passed to SetFieldsCount() the last time it was called.
268         @param styles
269             Contains an array of @a n integers with the styles for each field.
270             There are four possible styles:
271             - @c wxSB_NORMAL (default): The field appears with the default native border.
272             - @c wxSB_FLAT: No border is painted around the field so that it appears flat.
273             - @c wxSB_RAISED: A raised 3D border is painted around the field.
274             - @c wxSB_SUNKEN: A sunken 3D border is painted around the field
275               (this style is new since wxWidgets 2.9.5).
276     */
277     virtual void SetStatusStyles(int n, const int* styles);
278 
279     /**
280         Sets the status text for the @a i-th field.
281 
282         The given text will replace the current text. The display of the status
283         bar is updated immediately, so there is no need to call
284         wxWindow::Update() after calling this function.
285 
286         Note that if PushStatusText() had been called before the new text will
287         also replace the last saved value to make sure that the next call to
288         PopStatusText() doesn't restore the old value, which was overwritten by
289         the call to this function.
290 
291         @param text
292             The text to be set. Use an empty string ("") to clear the field.
293         @param i
294             The field to set, starting from zero.
295 
296         @see GetStatusText(), wxFrame::SetStatusText
297     */
298     virtual void SetStatusText(const wxString& text, int i = 0);
299 
300     /**
301         Sets the widths of the fields in the status line. There are two types of
302         fields: @b fixed widths and @b variable width fields. For the fixed width fields
303         you should specify their (constant) width in pixels. For the variable width
304         fields, specify a negative number which indicates how the field should expand:
305         the space left for all variable width fields is divided between them according
306         to the absolute value of this number. A variable width field with width of -2
307         gets twice as much of it as a field with width -1 and so on.
308 
309         For example, to create one fixed width field of width 100 in the right part of
310         the status bar and two more fields which get 66% and 33% of the remaining
311         space correspondingly, you should use an array containing -2, -1 and 100.
312 
313         @param n
314             The number of fields in the status bar. Must be equal to the
315             number passed to SetFieldsCount() the last time it was called.
316         @param widths_field
317             Contains an array of n integers, each of which is either an
318             absolute status field width in pixels if positive or indicates a
319             variable width field if negative.
320             The special value @NULL means that all fields should get the same width.
321 
322         @remarks The widths of the variable fields are calculated from the total
323                  width of all fields, minus the sum of widths of the
324                  non-variable fields, divided by the number of variable fields.
325 
326         @beginWxPerlOnly
327         In wxPerl this method takes as parameters the field widths.
328         @endWxPerlOnly
329 
330         @see SetFieldsCount(), wxFrame::SetStatusWidths()
331     */
332     virtual void SetStatusWidths(int n, const int* widths_field);
333 };
334 
335