home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / DOCVIEW.PAK / ODLISTBX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  7.1 KB  |  211 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1995 by Borland International, All Rights Reserved
  4. //
  5. //   Defines class TODListBox
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_ODLISTBX_H)
  8. #define OWL_ODLISTBX_H
  9.  
  10. #if !defined(OWL_CONTROL_H)
  11. # include <owl/control.h>
  12. #endif
  13.  
  14. class TODListBox : public TControl {
  15.   public:
  16.  
  17.     struct ODItemInfo { // temporary information about current item
  18.                    // the following are supplied to the GetItemInfo function:
  19.       HDC    Hdc;       // display context for listbox
  20.       int    Index;     // index of current item, set by Draw/MeasureItem
  21.       void far* Data;   // user item data value,  set by Draw/MeasureItem
  22.       uint   State;     // ODS_xxxx flags for new state, set by Draw/MeasureItem
  23.       TRect  Bound;     // actual drawing area bounds
  24.                    // the following are to be set by the GetItemInfo function:
  25.       TSize  Extent;    // cell size to display entire data
  26.       TPoint Offset;    // offset in rect of drawn data
  27.       char far* Text;   // pointer to text data to draw
  28.       int    TextLen;   // length of text data
  29.     };     
  30.  
  31.     TODListBox(int id);
  32.    ~TODListBox();
  33.  
  34.     // List box wrappers
  35.     //
  36.     virtual void  ClearList();
  37.     virtual int   GetCount() const;
  38.             int   GetTopIndex() const;
  39.             int   SetTopIndex(int index);
  40.             int   GetHorizontalExtent() const;
  41.             void  SetHorizontalExtent(int horzExtent);
  42.     virtual int   GetStringLen(int index) const;
  43.     virtual int   GetString(char far* str, int index) const;
  44.     virtual uint32 GetItemData(int index) const;
  45.     virtual int   SetItemData(int index, uint32 itemData);
  46.             int   GetItemRect(int index, TRect& rect) const;
  47.     virtual int   GetItemHeight(int index) const;
  48.     virtual int   SetItemHeight(int index, int height);
  49.     virtual int   AddString(const char far* str);
  50.     virtual int   InsertString(const char far* str, int index);
  51.     virtual int   DeleteString(int index);
  52.     virtual int   GetSelIndex() const;
  53.     virtual int   SetSelIndex(int index);
  54.  
  55.     //
  56.     // Override TWindow virtual member functions
  57.     //
  58.     char far     *GetClassName();
  59.  
  60.     virtual void ItemRedraw(int index);   // force item to be redrawn
  61.   protected:
  62.     int       MaxWidth; // maximum horizontal extent
  63.     char far* BufTemp;  // temporary buffer for returning strings
  64.     int       BufLen;      // allocated length of temporary buffer
  65.    
  66.     // Calls eminating from TControl for WM_DRAWITEM and WM_MEASUREITEM
  67.     //
  68.     virtual void  DrawItem (DRAWITEMSTRUCT far &);
  69.     virtual void  MeasureItem (MEASUREITEMSTRUCT far &);
  70.  
  71.     // Calls from TODListBox::DrawItem() which must be overridden if not text
  72.     //
  73.     virtual bool GetItemInfo  (ODItemInfo& item); // fill Offset, Text, TextLen
  74.     virtual void ChangeHilight(ODItemInfo& item);
  75.     virtual void ChangeFocus  (ODItemInfo& item);
  76.     virtual void DrawItemData (ODItemInfo& item);
  77.   private:
  78.  
  79.     // Hidden to prevent accidental copying or assignment
  80.     //
  81.     TODListBox(const TODListBox&);
  82.     TODListBox& operator=(const TODListBox&);
  83.  
  84.   DECLARE_STREAMABLE(, TODListBox, 1);
  85. };
  86.  
  87. //----------------------------------------------------------------------------
  88. // Inlines
  89. //
  90.  
  91. inline TODListBox::~TODListBox() {
  92.   if (BufTemp) delete BufTemp;
  93. }
  94.  
  95. inline int TODListBox::GetTopIndex() const {
  96.   return (int)CONST_CAST(TODListBox*,this)->SendMessage(LB_GETTOPINDEX);
  97. }
  98.  
  99. inline int TODListBox::SetTopIndex(int index) {
  100.   return (int)SendMessage(LB_SETTOPINDEX, index);
  101. }
  102.  
  103. inline int TODListBox::GetHorizontalExtent() const {
  104.   return (int)CONST_CAST(TODListBox*,this)->SendMessage(LB_GETHORIZONTALEXTENT);
  105. }
  106.  
  107. inline void TODListBox::SetHorizontalExtent(int horzExtent) {
  108.   SendMessage(LB_SETHORIZONTALEXTENT, horzExtent);
  109. }
  110.  
  111. inline uint32 TODListBox::GetItemData(int index) const {
  112.   return CONST_CAST(TODListBox*,this)->SendMessage(LB_GETITEMDATA, index);
  113. }
  114.  
  115. inline int TODListBox::SetItemData(int index, uint32 itemData) {
  116.   return (int)SendMessage(LB_SETITEMDATA, index, itemData);
  117. }
  118.  
  119. inline int TODListBox::GetItemRect(int index, TRect& rect) const {
  120.   return (int)CONST_CAST(TODListBox*,this)->
  121.            SendMessage(LB_GETITEMRECT, index, TParam2((TRect FAR*)&rect));
  122. }
  123.  
  124. inline int TODListBox::GetItemHeight(int index) const {
  125.   return (int)CONST_CAST(TODListBox*,this)->
  126.            SendMessage(LB_GETITEMHEIGHT, index);
  127. }
  128.  
  129. inline int TODListBox::SetItemHeight(int index, int height) {
  130.   return (int)SendMessage(LB_SETITEMHEIGHT, index, MkParam2(height, 0));
  131. }
  132.  
  133. //
  134. // Adds a string to an associated listbox
  135. // Returns index of the string in the list(the first entry is at index 0),
  136. // a negative if an error occurs.
  137. //
  138. inline int TODListBox::AddString(const char far* str) {
  139.   return (int)SendMessage(LB_ADDSTRING, 0, TParam2(str));
  140. }
  141.  
  142. //
  143. // Inserts a string in the associated listbox at the passed index,
  144. // returns the index of the string in the list, a negative if an error occurs
  145. //
  146. inline int TODListBox::InsertString(const char far* str, int index) {
  147.   return (int)SendMessage(LB_INSERTSTRING, index, TParam2(str));
  148. }
  149.  
  150. //
  151. // Deletes the string at the passed index in the associated listbox
  152. // Returns a count of the entries remaining in the list, a negative
  153. // value if an error occurs
  154. //
  155. inline int TODListBox::DeleteString(int index) {
  156.   return (int)SendMessage(LB_DELETESTRING, index);
  157. }
  158.  
  159. //
  160. // Clears all the entries in the associated listbox
  161. //
  162. inline void TODListBox::ClearList() {
  163.   SendMessage(LB_RESETCONTENT);
  164. }
  165.  
  166. //
  167. // Returns the number of entries in the associated listbox, a negative
  168. // value if an error occurs
  169. //
  170. inline int TODListBox::GetCount() const {
  171.   return (int)CONST_CAST(TODListBox*,this)->SendMessage(LB_GETCOUNT);
  172. }
  173.  
  174. //
  175. // Retrieves the contents of the string at the passed index of the
  176. // associated listbox. Returns the length of the string (in bytes
  177. // excluding the terminating 0),  a negative if the passed index is not valid
  178. //
  179. // The buffer must be large enough for the string and the terminating 0
  180. //
  181. inline int TODListBox::GetString(char far* str, int index) const {
  182.   return (int)CONST_CAST(TODListBox*,this)->
  183.            SendMessage(LB_GETTEXT, index, TParam2(str));
  184. }
  185.  
  186. //
  187. // Returns the length of the string at the passed index in the associated
  188. //
  189. // listbox excluding the terminating 0, a negative if an error occurs
  190. //
  191. inline int TODListBox::GetStringLen(int index) const {
  192.   return (int)CONST_CAST(TODListBox*,this)->SendMessage(LB_GETTEXTLEN, index);
  193. }
  194.  
  195. inline int TODListBox::GetSelIndex() const {
  196.   return (int)CONST_CAST(TODListBox*,this)->SendMessage(LB_GETCURSEL);
  197. }
  198.  
  199. //
  200. // selects the string at passed index in the associated listbox and
  201. // forces the string into view
  202. //
  203. // clears selection when -1 is passed as the index. a negative value is
  204. // returned if an error occurs
  205. //
  206. inline int TODListBox::SetSelIndex(int index) {
  207.   return (int)SendMessage(LB_SETCURSEL, index);
  208. }
  209.  
  210. #endif  // OWL_ODLISTBX_H
  211.