xref: /haiku/src/apps/cortex/InfoView/InfoView.h (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
1 /*
2  * Copyright (c) 1999-2000, Eric Moon.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions, and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 // InfoView.h (Cortex/InfoView)
33 //
34 // * PURPOSE
35 //   A base class for displaying info in a list of fields,
36 //   where each field has a label and the actual content text.
37 //   This class has to be subclassed for providing info on
38 //   specific objects, by adding fields to the view in the
39 //   constructor of the subclass. InfoView takes care of all
40 //   the display details, dynamically rearranging text on resize
41 //   if necessary.
42 //
43 // * TODO
44 //   Maybe add more field types, e.g. for options (checkboxes) or
45 //   dropdown-menus ?
46 //
47 // * HISTORY
48 //   c.lenz		5nov99		Begun
49 //
50 
51 #ifndef __InfoView_H__
52 #define __InfoView_H__
53 
54 // Interface Kit
55 #include <View.h>
56 // Support Kit
57 #include <String.h>
58 
59 #include "cortex_defs.h"
60 __BEGIN_CORTEX_NAMESPACE
61 
62 class InfoView :
63 	public BView {
64 
65 public:					// *** constants
66 
67 	// the default frame for an InfoView. Is not actually
68 	// needed right now, because the frame is set to an
69 	// 'ideal' size when the view is attached to the window
70 	static const BRect	M_DEFAULT_FRAME;
71 
72 	// defines how much space is used to separate objects
73 	// horizontally
74 	static const float	M_H_MARGIN;
75 
76 	// defines how much space is used to separate objects
77 	// vertically
78 	static const float	M_V_MARGIN;
79 
80 public:					// *** ctor/dtor
81 
82 	// creates a view containing only the title and subtitle
83 	// and the icon (if provided). No fields are defined here.
84 						InfoView(
85 							BString title,
86 							BString subTitle,
87 							BBitmap *icon);
88 
89 	virtual				~InfoView();
90 
91 public:					// *** BView impl.
92 
93 	// resizes the view to an 'ideal' size and inits linewrapping
94 	// for each field
95 	virtual void		AttachedToWindow();
96 
97 	// updates every fields linewrapping
98 	virtual void		FrameResized(
99 							float width,
100 							float height);
101 
102 	// returns the ideal size needed to display all text without
103 	// wrapping lines
104 	virtual void		GetPreferredSize(
105 							float *width,
106 							float *height);
107 
108 	// draws the title, subtitle, sidebar & icon as well as
109 	// every field
110 	virtual void		Draw(
111 							BRect updateRect);
112 
113 public:					// *** accessors
114 
115 	// adjusts the sidebars' width
116 	void				setSideBarWidth(
117 							float width)
118 						{ m_sideBarWidth = width; }
119 
120 	// returns the sidebars' width
121 	float				getSideBarWidth() const
122 						{ return m_sideBarWidth; }
123 
124 	// set the title (also used for window title)
125 	void				setTitle(
126 							BString title)
127 						{ m_title = title; }
128 
129 	// set the string which will be displayed just below
130 	// the title
131 	void				setSubTitle(
132 							BString subTitle)
133 						{ m_subTitle = subTitle; }
134 
135 protected:				// *** operations
136 
137 	// add a field with the given label and 'content'-text.
138 	// fields are displayed in the order they are added!
139 	// as there is no way to update the fields (yet), these
140 	// should always be added in the constructor of the
141 	// subclass!
142 	void				addField(
143 							BString label,
144 							BString text);
145 
146 private:				// *** data members
147 
148 	// the objects title, which will appear at top of the view
149 	// and in the windows titlebar
150 	BString				m_title;
151 
152 	// a string to be displayed right beneath the title, using a
153 	// smaller font
154 	BString				m_subTitle;
155 
156 	// an icon representation of the object
157 	BBitmap			   *m_icon;
158 
159 	// a list of the InfoTextField objects registered thru addField()
160 	BList			   *m_fields;
161 
162 	// the width of the sidebar holding label strings
163 	float				m_sideBarWidth;
164 
165 	// cached frame rect for proper redrawing of the sidebar
166 	BRect				m_oldFrame;
167 };
168 
169 __END_CORTEX_NAMESPACE
170 #endif /* __InfoView_H__ */
171