home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / src / common / lboxcmn.cpp < prev    next >
C/C++ Source or Header  |  2002-01-07  |  4KB  |  149 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name:        common/lboxcmn.cpp
  3. // Purpose:     wxListBox class methods common to all platforms
  4. // Author:      Vadim Zeitlin
  5. // Modified by:
  6. // Created:     22.10.99
  7. // RCS-ID:      $Id: lboxcmn.cpp,v 1.5 2002/01/07 21:52:28 GD Exp $
  8. // Copyright:   (c) wxWindows team
  9. // Licence:     wxWindows licence
  10. ///////////////////////////////////////////////////////////////////////////////
  11.  
  12. // ============================================================================
  13. // declarations
  14. // ============================================================================
  15.  
  16. // ----------------------------------------------------------------------------
  17. // headers
  18. // ----------------------------------------------------------------------------
  19.  
  20. #ifdef __GNUG__
  21.     #pragma implementation "listboxbase.h"
  22. #endif
  23.  
  24. // For compilers that support precompilation, includes "wx.h".
  25. #include "wx/wxprec.h"
  26.  
  27. #ifdef __BORLANDC__
  28.     #pragma hdrstop
  29. #endif
  30.  
  31. #if wxUSE_LISTBOX
  32.  
  33. #ifndef WX_PRECOMP
  34.     #include "wx/listbox.h"
  35. #endif
  36.  
  37. // ============================================================================
  38. // implementation
  39. // ============================================================================
  40.  
  41. wxListBoxBase::~wxListBoxBase()
  42. {
  43.     // this destructor is required for Darwin
  44. }
  45.  
  46. // ----------------------------------------------------------------------------
  47. // adding items
  48. // ----------------------------------------------------------------------------
  49.  
  50. void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
  51. {
  52.     wxArrayString aItems;
  53.     for ( int n = 0; n < nItems; n++ )
  54.     {
  55.         aItems.Add(items[n]);
  56.     }
  57.  
  58.     DoInsertItems(aItems, pos);
  59. }
  60.  
  61.  
  62. void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
  63. {
  64.     wxArrayString aItems;
  65.     for ( int n = 0; n < nItems; n++ )
  66.     {
  67.         aItems.Add(items[n]);
  68.     }
  69.  
  70.     DoSetItems(aItems, clientData);
  71. }
  72.  
  73. // ----------------------------------------------------------------------------
  74. // selection
  75. // ----------------------------------------------------------------------------
  76.  
  77. bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
  78. {
  79.     int sel = FindString(s);
  80.     wxCHECK_MSG( sel != -1, FALSE,
  81.                  wxT("invalid string in SetStringSelection") );
  82.  
  83.     SetSelection(sel, select);
  84.  
  85.     return TRUE;
  86. }
  87.  
  88. void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
  89. {
  90.     if ( HasMultipleSelection() )
  91.     {
  92.         wxArrayInt selections;
  93.         GetSelections(selections);
  94.  
  95.         size_t count = selections.GetCount();
  96.         for ( size_t n = 0; n < count; n++ )
  97.         {
  98.             int item = selections[n];
  99.             if ( item != itemToLeaveSelected )
  100.                 Deselect(item);
  101.         }
  102.     }
  103.     else // single selection
  104.     {
  105.         int sel = GetSelection();
  106.         if ( sel != -1 && sel != itemToLeaveSelected )
  107.         {
  108.             Deselect(sel);
  109.         }
  110.     }
  111. }
  112.  
  113. // ----------------------------------------------------------------------------
  114. // misc
  115. // ----------------------------------------------------------------------------
  116.  
  117. void wxListBoxBase::Command(wxCommandEvent& event)
  118. {
  119.     SetSelection(event.m_commandInt, event.m_extraLong != 0);
  120.     (void)ProcessEvent(event);
  121. }
  122.  
  123. // ----------------------------------------------------------------------------
  124. // SetFirstItem() and such
  125. // ----------------------------------------------------------------------------
  126.  
  127. void wxListBoxBase::SetFirstItem(const wxString& s)
  128. {
  129.     int n = FindString(s);
  130.  
  131.     wxCHECK_RET( n != -1, wxT("invalid string in wxListBox::SetFirstItem") );
  132.  
  133.     DoSetFirstItem(n);
  134. }
  135.  
  136. void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
  137. {
  138.     Append(s);
  139.     EnsureVisible(GetCount() - 1);
  140. }
  141.  
  142. void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
  143. {
  144.     // the base class version does nothing (the only alternative would be to
  145.     // call SetFirstItem() but this is probably even more stupid)
  146. }
  147.  
  148. #endif // wxUSE_LISTBOX
  149.