1 // InfoView.h (Cortex/InfoView) 2 // 3 // * PURPOSE 4 // A base class for displaying info in a list of fields, 5 // where each field has a label and the actual content text. 6 // This class has to be subclassed for providing info on 7 // specific objects, by adding fields to the view in the 8 // constructor of the subclass. InfoView takes care of all 9 // the display details, dynamically rearranging text on resize 10 // if necessary. 11 // 12 // * TODO 13 // Maybe add more field types, e.g. for options (checkboxes) or 14 // dropdown-menus ? 15 // 16 // * HISTORY 17 // c.lenz 5nov99 Begun 18 // 19 20 #ifndef __InfoView_H__ 21 #define __InfoView_H__ 22 23 // Interface Kit 24 #include <View.h> 25 // Support Kit 26 #include <String.h> 27 28 #include "cortex_defs.h" 29 __BEGIN_CORTEX_NAMESPACE 30 31 class InfoView : 32 public BView { 33 34 public: // *** constants 35 36 // the default frame for an InfoView. Is not actually 37 // needed right now, because the frame is set to an 38 // 'ideal' size when the view is attached to the window 39 static const BRect M_DEFAULT_FRAME; 40 41 // defines how much space is used to separate objects 42 // horizontally 43 static const float M_H_MARGIN; 44 45 // defines how much space is used to separate objects 46 // vertically 47 static const float M_V_MARGIN; 48 49 public: // *** ctor/dtor 50 51 // creates a view containing only the title and subtitle 52 // and the icon (if provided). No fields are defined here. 53 InfoView( 54 BString title, 55 BString subTitle, 56 BBitmap *icon); 57 58 virtual ~InfoView(); 59 60 public: // *** BView impl. 61 62 // resizes the view to an 'ideal' size and inits linewrapping 63 // for each field 64 virtual void AttachedToWindow(); 65 66 // updates every fields linewrapping 67 virtual void FrameResized( 68 float width, 69 float height); 70 71 // returns the ideal size needed to display all text without 72 // wrapping lines 73 virtual void GetPreferredSize( 74 float *width, 75 float *height); 76 77 // draws the title, subtitle, sidebar & icon as well as 78 // every field 79 virtual void Draw( 80 BRect updateRect); 81 82 public: // *** accessors 83 84 // adjusts the sidebars' width 85 void setSideBarWidth( 86 float width) 87 { m_sideBarWidth = width; } 88 89 // returns the sidebars' width 90 float getSideBarWidth() const 91 { return m_sideBarWidth; } 92 93 // set the title (also used for window title) 94 void setTitle( 95 BString title) 96 { m_title = title; } 97 98 // set the string which will be displayed just below 99 // the title 100 void setSubTitle( 101 BString subTitle) 102 { m_subTitle = subTitle; } 103 104 protected: // *** operations 105 106 // add a field with the given label and 'content'-text. 107 // fields are displayed in the order they are added! 108 // as there is no way to update the fields (yet), these 109 // should always be added in the constructor of the 110 // subclass! 111 void addField( 112 BString label, 113 BString text); 114 115 private: // *** data members 116 117 // the objects title, which will appear at top of the view 118 // and in the windows titlebar 119 BString m_title; 120 121 // a string to be displayed right beneath the title, using a 122 // smaller font 123 BString m_subTitle; 124 125 // an icon representation of the object 126 BBitmap *m_icon; 127 128 // a list of the InfoTextField objects registered thru addField() 129 BList *m_fields; 130 131 // the width of the sidebar holding label strings 132 float m_sideBarWidth; 133 134 // cached frame rect for proper redrawing of the sidebar 135 BRect m_oldFrame; 136 }; 137 138 __END_CORTEX_NAMESPACE 139 #endif /* __InfoView_H__ */ 140