wg_listbox.h

00001 // wg_listbox.h
00002 //
00003 // CListBox interface
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #ifndef _WG_LISTBOX_H_
00026 #define _WG_LISTBOX_H_
00027 
00028 #include "wg_window.h"
00029 #include "wg_painter.h"
00030 #include "wg_renderedstring.h"
00031 #include "wg_scrollbar.h"
00032 #include <vector>
00033 
00034 
00035 namespace wGui
00036 {
00037 
00039 
00040 struct SListItem
00041 {
00042 public:
00044      SListItem(std::wstring sItemTextIn, void* pItemDataIn = 0, CRGBColor ItemColorIn = DEFAULT_LINE_COLOR) :
00045           sItemText(sItemTextIn), pItemData(pItemDataIn), ItemColor(ItemColorIn) { }
00046 
00047      std::wstring sItemText;  
00048      void* pItemData;  
00049      CRGBColor ItemColor;  
00050 };
00051 
00052 
00054 
00057 
00058 class CListBox : public CWindow
00059 {
00060 public:
00068      CListBox(const CRect& WindowRect, CWindow* pParent, bool bSingleSelection = false, unsigned int iItemHeight = 15, CFontEngine* pFontEngine = 0);
00069 
00071      virtual ~CListBox(void);
00072 
00075      unsigned int GetItemHeight(void) { return m_iItemHeight; }
00076 
00079      void SetItemHeight(unsigned int iItemHeight);
00080 
00084      int AddItem(SListItem ListItem);
00085 
00089      SListItem& GetItem(int iItemIndex) { return m_Items.at(iItemIndex); }
00090 
00093      void RemoveItem(int iItemIndex);
00094 
00096      void ClearItems(void);
00097 
00100      int Size(void) { return stdex::safe_static_cast<int>(m_Items.size()); }
00101 
00104      bool IsSelected(int iItemIndex)
00105           { return (iItemIndex >= 0 && iItemIndex < stdex::safe_static_cast<int>(m_SelectedItems.size()) && m_SelectedItems.at(iItemIndex)); }
00106 
00109      int GetFirstSelectedIndex(void) const;
00110 
00114      void SetSelection(int iItemIndex, bool bSelected);
00115 
00118      void SetAllSelections(bool bSelected);
00119 
00122      void SetDropDown(CWindow* pDropDown) { m_pDropDown = pDropDown; }
00123 
00124 
00125      // CWindow overrides
00127      virtual void Draw(void) const;
00128 
00131      virtual void SetWindowRect(const CRect& WindowRect);
00132 
00137      virtual void PaintToSurface(SDL_Surface& ScreenSurface, SDL_Surface& FloatingSurface, const CPoint& Offset) const;
00138 
00144      virtual bool OnMouseButtonDown(CPoint Point, unsigned int Button);
00145 
00151      virtual bool OnMouseButtonUp(CPoint Point, unsigned int Button);
00152 
00153 
00154      // CMessageClient overrides
00157      virtual bool HandleMessage(CMessage* pMessage);
00158 
00159 
00160 protected:
00161      CFontEngine* m_pFontEngine;  
00162      CScrollBar* m_pVScrollbar;  
00163      unsigned int m_iItemHeight;  
00164      int m_iFocusedItem;  
00165      std::vector<SListItem> m_Items;  
00166      std::vector<bool> m_SelectedItems;  
00167      std::vector<CRenderedString> m_RenderedStrings;  
00168      const bool m_bSingleSelection;  
00169      CWindow* m_pDropDown;  
00170 
00171 
00172 private:
00173      void operator=(CListBox) { }  
00174 };
00175 
00176 }
00177 
00178 
00179 #include "unit_tests/wg_listbox_unittests.h"
00180 
00181 #endif  // _WG_LISTBOX_H_
00182 

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1