00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
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      
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      
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