home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / xferlist.cpp < prev    next >
C/C++ Source or Header  |  1994-05-26  |  3KB  |  154 lines

  1. #include <windows.h>
  2. #include <owl\applicat.h>
  3. #include <owl\button.h>
  4. #include <owl\framewin.h>
  5. #include <owl\listbox.h>
  6. #include <owl\static.h>
  7. #include <owl\window.h>
  8. #include <owl\window.rh>
  9.  
  10. #include "xferlist.h"
  11.  
  12. class TMyWindow : public TWindow
  13. {
  14. public:
  15.    TMyWindow(TWindow *parent = 0);
  16.    virtual ~TMyWindow();
  17.  
  18. protected:
  19.    virtual void SetupWindow();
  20.  
  21.    void CbToDst();
  22.    void CbToSrc();
  23.    void CmExit();
  24.  
  25. private:
  26.    TListBox *src, *dst;
  27.  
  28.    void MoveSels(TListBox *src, TListBox *dst);
  29.  
  30.    DECLARE_RESPONSE_TABLE(TMyWindow);
  31. };
  32. DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)
  33.    EV_COMMAND(CM_EXIT, CmExit),
  34.    EV_BN_CLICKED(IDB_TODST, CbToDst),
  35.    EV_BN_CLICKED(IDB_TOSRC, CbToSrc),
  36. END_RESPONSE_TABLE;
  37.  
  38. TMyWindow::TMyWindow(TWindow *parent)
  39. {
  40.    Init(parent, 0, 0);
  41.  
  42.    int   wbtn = 80,
  43.          hbtn = 30,
  44.          wlist = 150,
  45.          hlist = 250,
  46.          wspace = 30,
  47.          hspace = 50,
  48.          x0 = 30,
  49.          y0 = 50;
  50.    int   x = x0, y = y0;
  51.  
  52.    new TStatic(this, -1, "Source", x, y, wlist, hbtn);
  53.    y += hbtn;
  54.    if (NULL != (src = new TListBox(this, IDL_SRC, x, y, wlist, hlist)))
  55.       src->Attr.Style |= LBS_MULTIPLESEL;
  56.  
  57.    x += wlist + wspace;
  58.    y += hspace;
  59.    new TButton(this, IDB_TODST, "-->", x, y, wbtn, hbtn);
  60.    y += hbtn + hspace;
  61.    new TButton(this, IDB_TOSRC, "<--", x, y, wbtn, hbtn);
  62.  
  63.    x += wbtn + wspace;
  64.    y = y0;
  65.    new TStatic(this, -1, "Destination", x, y, wlist, hbtn);
  66.    y += hbtn;
  67.    if (NULL != (dst = new TListBox(this, IDL_DST, x, y, wlist, hlist)))
  68.       dst->Attr.Style |= LBS_MULTIPLESEL;
  69. }
  70.  
  71. TMyWindow::~TMyWindow()
  72. {
  73. }
  74.  
  75. void TMyWindow::SetupWindow()
  76. {
  77.    static char *names[] =
  78.       {  "Keith", "Bruce", "Kevin", "Bridget", "Kate",
  79.          "Kay", "Roger", "Marie", "Kathleen", "Liz",
  80.          "Ingrid", "Craig", "George", "Janet", "Gary",
  81.          "Helen", "Candace",
  82.          NULL };
  83.  
  84.    TWindow::SetupWindow();
  85.    
  86.    if (src)
  87.       for (int ix = 0; names[ix]; ++ix)
  88.          src->AddString(names[ix]);
  89. }
  90.  
  91. void TMyWindow::MoveSels(TListBox *src, TListBox *dst)
  92. {
  93.    if (src && dst)
  94.       {
  95.       int *sels, numsels = src->GetSelCount();
  96.       if ((numsels > 0) && (NULL != (sels = new int[numsels])))
  97.          {
  98.          int ix;
  99.  
  100.          src->GetSelIndexes(sels, numsels);
  101.          for (ix = 0; ix < numsels; ++ix)
  102.             {
  103.             char *str;
  104.             int size = src->GetStringLen(sels[ix]) + 1;
  105.             if ((size > 1) && (NULL != (str = new char[size])))
  106.                {
  107.                src->GetString(str, sels[ix]);
  108.                dst->AddString(str);
  109.                delete str;
  110.                }
  111.             }
  112.          for (ix = numsels - 1; ix >= 0; --ix)
  113.             src->DeleteString(sels[ix]);
  114.  
  115.          delete sels;
  116.          }
  117.       }
  118. }
  119.  
  120. void TMyWindow::CbToDst()
  121. {
  122.    MoveSels(src, dst);
  123. }
  124.  
  125. void TMyWindow::CbToSrc()
  126. {
  127.    MoveSels(dst, src);
  128. }
  129.  
  130. void TMyWindow::CmExit()
  131. {
  132.    SendMessage(WM_CLOSE);
  133. }
  134.  
  135. class TXferApp : public TApplication
  136. {
  137. public:
  138.    TXferApp() : TApplication()
  139.       { nCmdShow = SW_SHOWMAXIMIZED; }
  140.  
  141.    void InitMainWindow()
  142.       {
  143.       SetMainWindow(new TFrameWindow(  0,
  144.                            "Multiple Selection List Tester",
  145.                            new TMyWindow ));
  146.       GetMainWindow()->AssignMenu("EXITMENU");
  147.       }
  148. };
  149.  
  150. int OwlMain(int, char *[])
  151. {
  152.    return TXferApp().Run();
  153. }
  154.