📄 wg_listbox.h
字号:
// wg_listbox.h//// CListBox interface////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#ifndef _WG_LISTBOX_H_#define _WG_LISTBOX_H_#include "wg_window.h"#include "wg_painter.h"#include "wg_renderedstring.h"#include "wg_scrollbar.h"#include <vector>namespace wGui{//! A listbox itemstruct SListItem{public: //! Standard constructor SListItem(std::string sItemTextIn, void* pItemDataIn = 0, CRGBColor ItemColorIn = DEFAULT_LINE_COLOR) : sItemText(sItemTextIn), pItemData(pItemDataIn), ItemColor(ItemColorIn) { } std::string sItemText; //!< The displayed text for the item void* pItemData; //!< A pointer to void that can be used as a data pointer CRGBColor ItemColor; //!< The color to display the item in};//! A simple listbox class//! The button will generate CTRL_VALUECHANGE messages when a different listbox item is selected//! The iNewValue of the message is the index of the item that was selectedclass CListBox : public CWindow{public: //! Constructs a new listbox //! \param WindowRect A CRect that defines the outer limits of the control //! \param pParent A pointer to the parent window //! \param bSingleSelection If true, only one item can be selected at a time, defaults to false //! \param iItemHeight The height of the items in the list, defaults to 15 //! \param pFontEngine A pointer to the font engine to use when drawing the control //! If this is left out (or set to 0) it will use the default font engine specified by the CApplication (which must be set before instantiating this object) CListBox(const CRect& WindowRect, CWindow* pParent, bool bSingleSelection = false, unsigned int iItemHeight = 15, CFontEngine* pFontEngine = 0); //! Standard destructor virtual ~CListBox(void); //! \return The height of the items in the listbox unsigned int GetItemHeight(void) { return m_iItemHeight; } //! \param iItemHeight The height of the items in the listbox void SetItemHeight(unsigned int iItemHeight); //! Adds a new item to the list //! \param ListItem A SListItem structure with the data for the item //! \return The index of the added item int AddItem(SListItem ListItem); //! Returns the desired item //! \param iItemIndex The index of the item to check //! \return A reference to the SListItem struct SListItem& GetItem(int iItemIndex) { return m_Items[iItemIndex]; } //! Remove an item from the list //! \param iItemIndex The index of the item to remove void RemoveItem(int iItemIndex); //! Remove all items from the list void ClearItems(void); //! \return The number of items in the list int Size(void) { return static_cast<int>(m_Items.size()); } //! \param iItemIndex The index of the item to check //! \return true if the item is selected bool IsSelected(int iItemIndex) { return m_SelectedItems[iItemIndex]; } //! Set an item as selected //! \param iItemIndex The index of the item to change //! \param bSelected Will select the item if true, or unselect if false void SetSelection(int iItemIndex, bool bSelected) { m_SelectedItems[iItemIndex] = bSelected; } //! Set the selection for all of the items at once //! \param bSelected Will select all items if true, or unselect if false void SetAllSelections(bool bSelected); //! Set the dropdown window this is a part of //! \param pDropDown A pointer to the dropdown window void SetDropDown(CWindow* pDropDown) { m_pDropDown = pDropDown; } // CWindow overrides //! Draws the button and renders the button label virtual void Draw(void) const; //! Giving a control a new WindowRect will move and resize the control //! \param WindowRect A CRect that defines the outer limits of the control virtual void SetWindowRect(const CRect& WindowRect); //! This is called whenever the listbox is clicked on by the mouse //! Only the topmost window that bounds the point will be called by the system //! \param Point The point where the mouse clicked //! \param Button A bitfield indicating which button the window was clicked with //! \return True if it's in the bounds of the listbox virtual bool OnMouseButtonDown(CPoint Point, unsigned int Button); //! This is called whenever the a mouse button is released in the listbox //! Only the topmost window that bounds the point will be called by the system //! \param Point The point where the mouse clicked //! \param Button A bitfield indicating which button the window was clicked with //! \return True if it's in the bounds of the listbox virtual bool OnMouseButtonUp(CPoint Point, unsigned int Button); // CMessageClient overrides //! CListBoxes handle MOUSE_BUTTONDOWN, MOUSE_BUTTONUP and CTRL_VALUECHANGE messages //! \param pMessage A pointer to the message virtual bool HandleMessage(CMessage* pMessage);protected: CFontEngine* m_pFontEngine; //!< A pointer to the font engine to use to render the text CScrollBar* m_pVScrollbar; //!< A pointer to the vertical scrollbar unsigned int m_iItemHeight; //!< The height of the items in the list int m_iFocusedItem; //!< The currently focused item std::vector<SListItem> m_Items; //!< The list of items std::vector<bool> m_SelectedItems; //!< A vector of booleans indicating which items are selected std::vector<CRenderedString> m_RenderedStrings; //!< A vector of the rendered strings const bool m_bSingleSelection; //!< If true, only one item can be selected at a time CWindow* m_pDropDown; //!< A pointer to the dropdown control if this a part of oneprivate: void operator=(CListBox) { } //!< The assignment operator is not allowed for CWindow derived objects};}#endif // _WG_LISTBOX_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -