Fixed bug in using relative times eg "1 month ago".
[pwlib.git] / include / pwclib / toolbars.h
blobdc04e4f7849d0aa0d25b0af80cbc81c6e2d904e1
1 /*
2 * toolbars.h
4 * Tool Bar Interactor GUI classes.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
29 * $Log$
30 * Revision 1.22 1999/03/09 08:01:47 robertj
31 * Changed comments for doc++ support (more to come).
33 * Revision 1.21 1999/02/16 08:08:28 robertj
34 * MSVC 6.0 compatibility changes.
36 * Revision 1.20 1998/09/23 06:20:09 robertj
37 * Added open source copyright license.
39 * Revision 1.19 1996/04/30 12:34:10 robertj
40 * Changed "inPixels" boolean to enum for three coordinate systems.
42 * Revision 1.18 1995/10/14 15:11:59 robertj
43 * Fixed bug in changing fonts on status bar.
45 * Revision 1.17 1995/07/31 12:13:03 robertj
46 * Added balloon help string to toolbar button codes.
48 * Revision 1.16 1995/06/17 11:13:39 robertj
49 * Documentation update.
51 * Revision 1.15 1995/06/04 12:38:26 robertj
52 * Redesign to add vertical tool bars and control wrapping.
54 * Revision 1.14 1995/04/02 09:27:35 robertj
55 * Added "balloon" help.
57 * Revision 1.13 1995/03/22 13:51:17 robertj
58 * Split SetText() to separate function for SetSectionText() to guarentee that
59 * the parameters can be resolved.
61 * Revision 1.12 1995/03/14 12:42:54 robertj
62 * Updated documentation to use HTML codes.
64 * Revision 1.11 1995/02/19 04:19:23 robertj
65 * Added dynamically linked command processing.
67 * Revision 1.10 1995/01/18 09:04:12 robertj
68 * Added initialiser arrays for button bar and status bar.
69 * Documentation.
71 * Revision 1.9 1995/01/15 04:53:11 robertj
72 * Fixed problems with stdarg and PString parameter on GNU compiler.
74 * Revision 1.8 1995/01/10 11:44:36 robertj
75 * Removed PString parameter in stdarg function for GNU C++ compatibility.
77 * Revision 1.7 1994/10/30 11:47:26 robertj
78 * Changed mechanism for doing notification callback functions.
80 * Revision 1.6 1994/08/23 11:32:52 robertj
81 * Oops
83 * Revision 1.5 1994/08/22 00:46:48 robertj
84 * Added pragma fro GNU C++ compiler.
86 * Revision 1.4 1994/08/21 23:43:02 robertj
87 * Changed parameter before variable argument list to NOT be a reference.
89 * Revision 1.3 1994/08/04 01:43:48 robertj
90 * Removed comments.
92 * Revision 1.2 1994/07/27 05:58:07 robertj
93 * Synchronisation.
95 * Revision 1.1 1994/04/01 14:25:36 robertj
96 * Initial revision
100 #ifndef _PTOOLBARS
101 #define _PTOOLBARS
103 #ifdef __GNUC__
104 #pragma interface
105 #endif
108 /**A class representing a tool bar. This is an interactor layout containing
109 a series of controls and having a "chiselled" 3-d boundary. The controls
110 added to the tool bar are automatically positioned according to some
111 simple rules.
113 The bar may be horizontal or vertical. The actual positioning of the bar
114 is usually determined by the parent interactor positioning it using the
115 \ref{PInteractor::AutoAdjustBounds()} function.
117 A horizontal bar positions controls added across a row with optional
118 wrapping to the next row when passed the end of the bar. A vertical bar
119 positions controls down in a column optionally wrapping to a new column
120 when beyond the bottom of the bar.
122 Functionaly, this is very similar to a non-modal dialog but has a different
123 "look", that is does not have a title bar and cannot be moved under user
124 control.
126 A tool bar is mainly used as the ancestor to the standard classes
127 \ref{PButtonBar} and \ref{PStatusBar}.
129 class PToolBar : public PInteractorLayout
131 PCLASSINFO(PToolBar, PInteractorLayout);
133 public:
134 /**@name Construction */
135 //@{
136 /**Create a new empty tool bar. The #vertical# parameter
137 indicates that the controls are positioned down the bar. The
138 #autoWrap# parameter indicates that controls added beyond
139 the right (or bottom) of the bar are repositioned to the left (or top)
140 and below (or next to) the previous row (or column).
142 PToolBar(
143 PInteractor * parent, /// Parent interactor for the tool bar.
144 BOOL vertical = FALSE, /// Tool bar is vertical.
145 BOOL autoWrap = FALSE /// Wrap controls at end of bar.
147 //@}
150 /**@name New functions for class */
151 //@{
152 /**Add a control to the tool bar. The new control is placed next to the
153 last control added adjusting its position.
155 void AddControl(
156 PControl * control, /// Control to add to the list of automatically.
157 PDIMENSION gapSize = 0,
158 /// Amount "gap units" to leave between this control and the next one.
159 PDIMENSION elasticity = 0
160 /**Elasticity of control, 0 is may not be resized. A non-zero value
161 is the ratio of all elastic controls to be resized when the size of
162 the bar is changed.
165 //@}
167 protected:
168 /**@name Overrides from class PInteractor */
169 //@{
170 virtual void _SetDimensions(
171 PDIMENSION width, // New width to apply to interactor.
172 PDIMENSION height, // New height to apply to interactor.
173 CoordinateSystem coords // Coordinate system to use.
175 /* Set the dimensions of the status bar. The new size is specified in
176 either the font based layout coordinates or in screen pixels as
177 specified by the #coords# parameter.
179 All static text sections within the status bar are resized according
180 to their relative and absolute widths.
182 When scaling is used (#coords == LocalCoords#), the
183 coordinates used are 1/4 average font width and 1/8 the font height.
186 virtual void OnRedraw(
187 PCanvas & canvas // Canvas to use when drawing the interactor contents.
189 /* The system calls this whenever it requires that the interactors usable
190 area needs to be updated and redrawn.
192 The behaviour here is to draw the "chiselled" 3-d look of a tool bar.
196 virtual PBalloon * OnBalloonHelp();
197 /* This function is called whenever a balloon help function for the
198 interactor is required.
200 @return
201 Pointer to balloon window containing balloon help text.
203 //@}
205 /**@name New functions for class */
206 //@{
207 void DoControlGeometry();
208 // Do the geometry calculations for the controls in the bar.
209 //@}
212 // Member variables
213 class BarItem : public PObject
215 PCLASSINFO(BarItem, PObject);
216 public:
217 BarItem(PControl * c, PDIMENSION g, PDIMENSION e)
218 : control(c), gapSize(g), elasticity(e) { }
219 PControl * control;
220 PDIMENSION gapSize;
221 PDIMENSION elasticity;
223 PLIST(BarItems, BarItem);
224 BarItems item;
225 PDim margin;
226 BOOL positionDown;
227 BOOL wrapControls;
231 /**A class representing a tool bar consisting of a series of picture button
232 controls. The picture for the button is loaded from a resource with the
233 specified number in the array pass to the constructor. This number is
234 then used as the control ID for thge picture button. When one of these
235 buttons is pressed the specified ID is again used in determining which
236 main menu item to simulate.
238 class PButtonBar : public PToolBar
240 PCLASSINFO(PButtonBar, PToolBar);
242 public:
243 /**@name Construction */
244 //@{
245 /** Initialisation structure for static array of button definitions
247 struct ButtonID {
248 /**Resource ID of the "linked" menu item. Pressing the button will be
249 equivalent to selecting this menu item.
251 PRESOURCE_ID menuItem;
252 /**The name of the \ref{PCommandSink} that will be executed when the
253 button is pressed. This is also used to enable/disable the button.
255 const char * commandName;
256 /**Resource ID of the image when the button is enabled. If this is zero
257 then the #menuItem# field is used.
259 PRESOURCE_ID enabledImage;
260 /**Resource ID of the image when the button is disabled. If this is zero
261 then the #enabledImage# field is used. If that field is
262 also zero then the #menuItem# field is used.
264 PRESOURCE_ID disabledImage;
265 /**Resource ID of the string to be used as the balloon help. If this is
266 zero then the #menuItem# field is used.
268 PRESOURCE_ID balloonHelp;
271 /** Create a new button bar.
273 PButtonBar(
274 PInteractor * parent, /// Parent interactor for button bar.
275 const ButtonID * IDs, /// Array of button identifier structures.
276 PINDEX numIDs, /// Number of button identifier structures.
277 BOOL vertical = FALSE, /// Tool bar is vertical.
278 BOOL autoWrap = FALSE /// Wrap controls at end of bar.
280 //@}
282 /**@name New functions for class */
283 //@{
284 /**Add a list of image buttons to the button bar.
286 void AddButtons(
287 const ButtonID * IDs, /// Array of button identifier structures.
288 PINDEX numIDs /// Number of button identifier structures.
290 //@}
293 protected:
294 /**@name Overrides from PInteractor */
295 //@{
296 virtual void OnControlNotify(
297 PControl & control, // Control that provides the notification.
298 int option // Options for the type of notification.
300 /* This function is called whenever a control needs to notify its parent
301 interactor that somthing has happened to it.
303 The behaviour here is to call the
304 \ref{PTopLevelWindow::OnMenuItemSelect()} function for the menu item if
305 the ID specified for the image button.
307 //@}
311 /**A class representing a tool bar consisting of a series of static text
312 controls with 3-D borders. The static text sections may be optionaly of
313 a fixed width or dynamically resized when the status bar has its size
314 changed.
316 This is typically used at the bottom of a window to indicate status and
317 short message displays.
319 class PStatusBar : public PToolBar
321 PCLASSINFO(PStatusBar, PToolBar);
323 public:
324 /**@name Construction */
325 //@{
326 /**Create a new status bar with the specified number of static text
327 descendent controls as sections of the bar.
329 PStatusBar(
330 PInteractor * parent, // Parent interactor for the status bar.
331 PINDEX numSections // Number of sections in the status bar.
333 //@}
335 /**@name Overrides from PInteractor */
336 //@{
337 /**Set the font to be used by default by this interactor. A canvas created
338 on this interactor will initially have this font selected.
340 virtual void SetFont(
341 const PFont & newFont, /// New font specification fo rthe interactor.
342 BOOL toChildren = TRUE
343 /// Flag to recursively change all child interactors.
345 //@}
347 /**@name New functions for class */
348 //@{
349 /**Set the text in the first section. */
350 void SetText(
351 const PString & str /// New text string for section
353 /**Set the text in the first section. */
354 void SetText(
355 PRESOURCE_ID resId,
356 /// Printf style format resource string for variable arguments.
359 /**Set the text in the first section.
361 The text may be set using printf style variable arguments. If this is
362 done then the format string cannot be a \ref{PString} instance due to
363 limitations in some compilers.
365 If no section number is specified then the first section is set.
367 void SetText(
368 const char * fmt, /// Printf style format string for variable arguments.
372 /**Set the text in the section number specified. */
373 void SetSectionText(
374 PINDEX section, /// Number of static text section to change.
375 const PString & str /// New text string for section
377 /**Set the text in the section number specified. */
378 void SetSectionText(
379 PINDEX section, /// Number of static text section to change.
380 PRESOURCE_ID resId,
381 /// Printf style format resource string for variable arguments.
384 /**Set the text in the section number specified. The first section is
385 numbered zero.
387 The text may be set using printf style variable arguments. If this is
388 done then the format string cannot be a \ref{PString} instance due to
389 limitations in some compilers.
391 If no section number is specified then the first section is set.
393 void SetSectionText(
394 PINDEX section, /// Number of static text section to change.
395 const char * fmt, /// Printf style format string for variable arguments.
399 /**Set the width of each section in the status bar. */
400 void SetSectionWidth(
401 PINDEX section, /// Number of static text section to change.
402 const PString & str /// Longest text string to put into section.
404 /**Set the width of each section in the status bar. */
405 void SetSectionWidth(
406 PINDEX section, /// Number of static text section to change.
407 const PRESOURCE_ID * strIDs, /// Array of string resource identifiers.
408 PINDEX nStrings /// Number of string resource identifiers.
410 /**Set the width of each section in the status bar.
412 The first form will set the width to sufficient to contain the string
413 specified, in the status bars currently selected font.
415 The second form sets the width to the widest string in the specified
416 array of resource strings.
418 The final form sets the width directly. A positive value specifies the
419 fixed width if the section in the interactors font based coordinate
420 system.
422 A negative width here will specify a ratio to be used when dividing the
423 total remaining bar width amongst all sections with negative widths.
425 If a section has its width changed after the status bar is shown then
426 an explicit call to the \ref{PInteractor::SetDimensions()} function
427 must be made to resize all of the sections.
429 The default width for a section is -1.
431 void SetSectionWidth(
432 PINDEX section, /// Number of static text section to change.
433 int width /// Width of the section.
436 /**Set the text alignement options for the specified section. */
437 void SetSectionAlignment(
438 PINDEX section, /// Number of static text section to change.
439 PCanvas::DrawStringOptions align /// text alignment for section.
441 //@}
443 protected:
444 class Section : public PStaticText
446 PCLASSINFO(Section, PStaticText);
447 public:
448 Section(PInteractor * parent);
449 protected:
450 virtual void OnRedraw(PCanvas & canvas);
451 friend class PStatusBar;
455 /**Get the specified section of the status bar. This will assert if the
456 section does not exist or is not a descendent of the
457 #PStatusBar::Section# class.
459 @return
460 a reference to the section.
462 Section & GetSection(
463 PINDEX section /// Number of section to get.
464 ) const;
468 #endif
470 // End Of File ///////////////////////////////////////////////////////////////