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