home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / MSWSRC35 / MYCOMBO.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  3KB  |  92 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* -------------------------------------------------------
  4. MYCOMBO.CPP
  5. Defines type TMyComboBox.  This is a replacement for TComboBox which
  6. differs solely in that it uses a TNSCollection as part of its
  7. transferbuffer instead of an Array.
  8. Note that if you actually intend to stream this class, you will
  9. need to define the build, read, write, etc. needed, since this
  10. will class will otherwise use those inherited from TComboBox.
  11. -------------------------------------------------------- */
  12.  
  13. #include <owl.h>
  14.  
  15. #include "mycombo.h"
  16.  
  17. /* Constructor for a TMyComboBoxData object. Initializes Strings and
  18. Selection. */
  19. TMyComboBoxData::TMyComboBoxData()
  20.    {
  21.    Strings = new TNSCollection(5, 5);
  22.    Selection = NULL;
  23.    }
  24.  
  25. /* Destructor for TMyComboBoxData. Deletes Strings and Selection. */
  26. TMyComboBoxData::~TMyComboBoxData()
  27.    {
  28.    if ( Strings )
  29.    delete Strings;
  30.    if ( Selection )
  31.    delete Selection;
  32.    }
  33.  
  34. /* Adds the supplied string to the Strings Array and copies it into
  35. Selection if IsSelected is TRUE. */
  36. void TMyComboBoxData::AddString(Pchar AString, BOOL IsSelected)
  37.    {
  38.    Strings->insert(strdup(AString));
  39.    if ( IsSelected )
  40.       {
  41.       if (AString != Selection)
  42.          {
  43.          if (Selection)
  44.          delete Selection;
  45.          Selection = strdup(AString);
  46.          }
  47.       }
  48.    }
  49.  
  50. static void DoAddForCB(Pvoid AString, Pvoid AComboBox)
  51.    {
  52.    if (AString)
  53.    ((PTMyComboBox)AComboBox)->AddString((Pchar)AString);
  54.    }
  55.  
  56. /* Transfers the items and selection of the combo box to or from a
  57. transfer buffer if TF_SETDATA or TF_GETDATA, repectively, is passed
  58. as the TransferFlag. DataPtr should point to a PTMyComboBoxData
  59. (i.e. it should be a pointer to a pointer to a TMyComboBoxData)
  60. which points to the data to be transferred.
  61. Transfer returns the size of PTMyComboBox (the pointer not the
  62. object). To retrieve the size without transferring data, pass
  63. TF_SIZEDATA as the TransferFlag. */
  64. WORD TMyComboBox::Transfer(Pvoid DataPtr, WORD TransferFlag)
  65.    {
  66.    PTMyComboBoxData ComboBoxData = *(PTMyComboBoxData _FAR *)DataPtr;
  67.    
  68.    if ( TransferFlag == TF_GETDATA )
  69.       {
  70.       int StringSize = GetWindowTextLength(HWindow) + 1;
  71.       if (!StringSize)
  72.       StringSize = 80;
  73.       if ( ComboBoxData->Selection )
  74.       delete ComboBoxData->Selection;
  75.       ComboBoxData->Selection= new char[StringSize];
  76.       GetWindowText(HWindow, ComboBoxData->Selection, StringSize);
  77.       }
  78.    else
  79.    if ( TransferFlag == TF_SETDATA )
  80.       {
  81.       ClearList();
  82.       ComboBoxData->Strings->forEach(DoAddForCB, this);
  83.       
  84.       int SelIndex = FindExactString(ComboBoxData->Selection, -1);
  85.       if ( SelIndex > -1 )
  86.       SetSelIndex(SelIndex);
  87.       
  88.       SetWindowText(HWindow, ComboBoxData->Selection);
  89.       }
  90.    return sizeof(PTMyComboBoxData);
  91.    }
  92.