home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / COMBOBOX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  9.9 KB  |  308 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   include\owl\combobox.h
  4. //   Defines class TComboBox and TComboBoxData.  This defines the basic
  5. //   behavior of all combo box controls.
  6. //----------------------------------------------------------------------------
  7. #if !defined(__OWL_COMBOBOX_H)
  8. #define __OWL_COMBOBOX_H
  9.  
  10. #if !defined(__OWL_LISTBOX_H)
  11.   #include <owl\listbox.h>
  12. #endif
  13.  
  14. //
  15. //  class TComboBox
  16. //  ----- ---------
  17. //
  18. class _OWLCLASS TComboBox : public TListBox {
  19.   public:
  20.     UINT  TextLen;
  21.  
  22.     TComboBox(TWindow*        parent,
  23.               int             id,
  24.               int x, int y, int w, int h,
  25.               DWORD           style,
  26.               UINT            textLen,
  27.               TModule*        module = 0);
  28.  
  29.     TComboBox(TWindow*   parent,
  30.               int        resourceId,
  31.               UINT       textLen = 0,
  32.               TModule*   module = 0);
  33.  
  34.     //
  35.     // for combo box's edit control
  36.     //
  37.     int           GetTextLen() const {return GetWindowTextLength();}
  38.     int           GetText(char far* str, int maxChars) const;  // num of chars copied
  39.     void          SetText(const char far* str);
  40.  
  41.     int           GetEditSel(int& startPos, int& endPos);
  42.     int           SetEditSel(int startPos, int endPos);  //CB_ERR if no edit control
  43.  
  44.     void          Clear();  // clear the text
  45.  
  46.     //
  47.     // for drop down combo boxes
  48.     //
  49.     void          ShowList(BOOL show);
  50.     void          ShowList() {ShowList(TRUE);}
  51.     void          HideList() {ShowList(FALSE);}
  52.  
  53.     void          GetDroppedControlRect(TRect& Rect) const;
  54.     BOOL          GetDroppedState() const;
  55.     BOOL          GetExtendedUI() const;
  56.     int           SetExtendedUI(BOOL Extended);
  57.  
  58.     //
  59.     // Combo's List box virtual functions
  60.     //
  61.     virtual int   AddString(const char far* str);
  62.     virtual int   InsertString(const char far* str, int index);
  63.     virtual int   DeleteString(int index);
  64.  
  65.     virtual void  ClearList();
  66.     virtual int   DirectoryList(UINT attrs, const char far* fileSpec);
  67.  
  68.     virtual int   GetCount() const;
  69.     virtual int   FindString(const char far* find, int indexStart) const;
  70.  
  71.     virtual int   GetStringLen(int index) const;
  72.     virtual int   GetString(char far* str, int index) const;
  73.  
  74.     virtual int   GetSelIndex() const;
  75.     virtual int   SetSelIndex(int index);
  76.     virtual int   SetSelString(const char far* findStr, int indexStart);
  77.     virtual DWORD GetItemData(int index) const;
  78.     virtual int   SetItemData(int index, DWORD itemData);
  79.  
  80.     int           GetItemHeight(int index) const;
  81.     int           SetItemHeight(int index, int height);
  82.  
  83.     //
  84.     // Override TWindow virtual member functions
  85.     //
  86.     UINT          Transfer(void* buffer, TTransferDirection direction);
  87.  
  88.   protected:
  89.     //
  90.     // Override TWindow virtual member functions
  91.     //
  92.     char far*     GetClassName();
  93.     void          SetupWindow();
  94.  
  95.     //
  96.     // message response functions
  97.     //
  98.  
  99.   private:
  100.     //
  101.     // hidden to prevent accidental copying or assignment
  102.     //
  103.     TComboBox(const TComboBox&);
  104.     TComboBox& operator =(const TComboBox&);
  105.  
  106.   DECLARE_STREAMABLE(_OWLCLASS, TComboBox, 1);
  107. };
  108.  
  109. //
  110. // combo box notification macros. methods are: void method()
  111. //
  112. // EV_CBN_CLOSEUP(id, method)
  113. // EV_CBN_DBLCLK(id, method)
  114. // EV_CBN_DROPDOWN(id, method)
  115. // EV_CBN_EDITCHANGE(id, method)
  116. // EV_CBN_EDITUPDATE(id, method)
  117. // EV_CBN_ERRSPACE(id, method)
  118. // EV_CBN_KILLFOCUS(id, method)
  119. // EV_CBN_SELCHANGE(id, method)
  120. // EV_CBN_SELENDCANCEL(id, method)
  121. // EV_CBN_SELENDOK(id, method)
  122. // EV_CBN_SETFOCUS(id, method)
  123.  
  124. //
  125. //  class TComboBoxData
  126. //  ----- -------------
  127. //
  128. class _OWLCLASS TComboBoxData {
  129.   public:
  130.     TComboBoxData();
  131.    ~TComboBoxData();
  132.  
  133.     TStringArray&   GetStrings() {return Strings;}
  134.     TDwordArray&    GetItemDatas() {return ItemDatas;}
  135.     int             GetSelIndex() {return SelIndex;}
  136.     string&         GetSelection() {return Selection;}
  137.  
  138.     void    AddString(const char* str, BOOL isSelected = FALSE);
  139.     void    AddStringItem(const char* str, DWORD itemData, BOOL isSelected = FALSE);
  140.     void    Clear() {Strings.Flush(); ItemDatas.Flush(); ResetSelections();}
  141.  
  142.     void    Select(int index);
  143.     void    SelectString(const char far* str);
  144.     int     GetSelCount() const {return SelIndex == CB_ERR ? 0 : 1;}
  145.     void    ResetSelections() {SelIndex = CB_ERR;  Selection = "";}
  146.     int     GetSelStringLength() const;
  147.     void    GetSelString(char far* buffer, int bufferSize) const;
  148.  
  149.   protected:
  150.     TStringArray   Strings;
  151.     TDwordArray    ItemDatas;
  152.     string         Selection;
  153.     int            SelIndex;
  154. };
  155.  
  156. //----------------------------------------------------------------------------
  157. // Inlines for class TComboBox
  158. //----------------------------------------------------------------------------
  159.  
  160. inline void TComboBox::Clear() {SetText(0);}
  161.  
  162. inline int TComboBox::GetText(char far* str, int maxChars) const {
  163.   return GetWindowText(str, maxChars);
  164. }
  165.  
  166. inline int TComboBox::SetEditSel(int startPos, int endPos) {
  167.   return (int)HandleMessage(CB_SETEDITSEL, 0, MAKELPARAM(startPos, endPos));
  168. }
  169.  
  170. inline void TComboBox::GetDroppedControlRect(TRect& rect) const {
  171.   CONST_CAST(TComboBox*,this)->
  172.     HandleMessage(CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)(TRect FAR*)&rect);
  173. }
  174.  
  175. inline BOOL TComboBox::GetDroppedState() const {
  176.   return (BOOL)CONST_CAST(TComboBox*,this)->HandleMessage(CB_GETDROPPEDSTATE);
  177. }
  178.  
  179. inline BOOL TComboBox::GetExtendedUI() const {
  180.   return (BOOL)CONST_CAST(TComboBox*,this)->HandleMessage(CB_GETEXTENDEDUI);
  181. }
  182.  
  183. inline int TComboBox::SetExtendedUI(BOOL extended) {
  184.   return (BOOL)HandleMessage(CB_SETEXTENDEDUI, extended);
  185. }
  186.  
  187. //
  188. // Adds a string to the list part of the associated combobox
  189. // Returns index of the string in the list(the first entry is at index 0)
  190. // A negative value is returned if an error occurs
  191. //
  192. inline int TComboBox::AddString(const char far* str) {
  193.   return (int)HandleMessage(CB_ADDSTRING, 0, (LPARAM)str);
  194. }
  195.  
  196. //
  197. // Inserts a string in list part of the associated combobox at the passed
  198. // index, returning the index of the string in the list
  199. // A negative value is returned if an error occurs
  200. //
  201. inline int TComboBox::InsertString(const char far* str, int index) {
  202.   return (int)HandleMessage(CB_INSERTSTRING, index, (LPARAM)str);
  203. }
  204.  
  205. //
  206. // Deletes the string at the passed index in the list part of the associated combobox
  207. // Returns a count of the entries remaining in the list; A negative
  208. // value is returned if an error occurs
  209. //
  210. inline int TComboBox::DeleteString(int index) {
  211.   return (int)HandleMessage(CB_DELETESTRING, index);
  212. }
  213.  
  214. inline int TComboBox::DirectoryList(UINT attrs, const char far* fileSpec) {
  215.   return (int)HandleMessage(CB_DIR, attrs,(LPARAM)fileSpec);
  216. }
  217.  
  218. //
  219. // Clears all the entries in list part of the associated combobox
  220. //
  221. inline void TComboBox::ClearList() {
  222.   HandleMessage(CB_RESETCONTENT);
  223. }
  224.  
  225. //
  226. // Returns the number of entries in list part of the associated combobox. a negative
  227. // value is returned if an error occurs
  228. //
  229. inline int TComboBox::GetCount() const {
  230.   return (int)CONST_CAST(TComboBox*,this)->HandleMessage(CB_GETCOUNT);
  231. }
  232.  
  233. //
  234. // Returns the index of the first string in list part of the associated combobox which
  235. // begins with the passed string
  236. //
  237. // Searches for a match beginning at the passed SearchIndex. If a match is
  238. // not found after the last string has been compared, the search continues
  239. // from the beginning of the list until a match is found or until the list
  240. // has been completely traversed
  241. //
  242. // Searches from beginning of list when -1 is passed as the index
  243. //
  244. // Returns the index of the selected string.  A negative value is returned
  245. // if an error occurs
  246. //
  247. inline int TComboBox::FindString(const char far* find, int indexStart) const {
  248.   return (int)CONST_CAST(TComboBox*,this)->
  249.            HandleMessage(CB_FINDSTRING, indexStart,(LPARAM)find);
  250. }
  251.  
  252. //
  253. // Retrieves the contents of the string at the passed index of list part of
  254. // the associated combobox, returning the length of the string (in bytes
  255. // excluding the terminating 0) as the value of the call
  256. //
  257. // A negative value is returned if the passed index is not valid
  258. //
  259. // The buffer must be large enough for the string and the terminating
  260. // 0
  261. //
  262. inline int TComboBox::GetString(char far* str, int index) const {
  263.   return (int)CONST_CAST(TComboBox*,this)->
  264.            HandleMessage(CB_GETLBTEXT, index, (LPARAM)str);
  265. }
  266.  
  267. //
  268. // Returns the length of the string at the passed index in the
  269. // associated combo list excluding the terminating 0
  270. //
  271. // A negative value is returned if an error occurs
  272. //
  273. inline int TComboBox::GetStringLen(int index) const {
  274.   return (int)CONST_CAST(TComboBox*,this)->
  275.            HandleMessage(CB_GETLBTEXTLEN, index);
  276. }
  277.  
  278. inline int TComboBox::GetSelIndex() const {
  279.   return (int)CONST_CAST(TComboBox*,this)->HandleMessage(CB_GETCURSEL);
  280. }
  281.  
  282. inline int TComboBox::SetSelIndex(int index) {
  283.   return (int)HandleMessage(CB_SETCURSEL, index);
  284. }
  285.  
  286. inline int TComboBox::SetSelString(const char far* findStr, int indexStart) {
  287.   return (int)HandleMessage(CB_SELECTSTRING, indexStart, (LPARAM)findStr);
  288. }
  289.  
  290. inline DWORD TComboBox::GetItemData(int index) const {
  291.   return CONST_CAST(TComboBox*,this)->HandleMessage(CB_GETITEMDATA, index);
  292. }
  293.  
  294. inline int TComboBox::SetItemData(int index, DWORD itemData) {
  295.   return (int)HandleMessage(CB_SETITEMDATA, index, itemData);
  296. }
  297.  
  298. inline int TComboBox::GetItemHeight(int index) const {
  299.   return (int)CONST_CAST(TComboBox*,this)->
  300.            HandleMessage(CB_GETITEMHEIGHT, index);
  301. }
  302.  
  303. inline int TComboBox::SetItemHeight(int index, int height) {
  304.   return (int)HandleMessage(CB_GETITEMHEIGHT, index, MAKELPARAM(height,0));
  305. }
  306.  
  307. #endif  // __OWL_COMBOBOX_H
  308.