📄 wg__listbox_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>wg_listbox.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_listbox.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_listbox.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CListBox class implementation</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 00025 <span class="preprocessor">#include "wgui_include_config.h"</span>00026 <span class="preprocessor">#include "wg_listbox.h"</span>00027 <span class="preprocessor">#include "wg_application.h"</span>00028 <span class="preprocessor">#include "wg_message_server.h"</span>00029 <span class="preprocessor">#include "wg_error.h"</span>00030 <span class="preprocessor">#include "wg_debug.h"</span>00031 00032 <span class="keyword">namespace </span>wGui00033 {00034 <a name="l00035"></a><a class="code" href="classwGui_1_1CListBox.html#a0">00035</a> CListBox::CListBox(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& WindowRect, <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pParent, <span class="keywordtype">bool</span> bSingleSelection, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iItemHeight, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine) :00036 <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00037 m_iItemHeight(iItemHeight),00038 m_iFocusedItem(0),00039 m_bSingleSelection(bSingleSelection),00040 m_pDropDown(0)00041 {00042 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CListBox"</span>;00043 <span class="keywordflow">if</span> (pFontEngine)00044 {00045 <a class="code" href="classwGui_1_1CListBox.html#n0">m_pFontEngine</a> = pFontEngine;00046 }00047 <span class="keywordflow">else</span>00048 {00049 <a class="code" href="classwGui_1_1CListBox.html#n0">m_pFontEngine</a> = CApplication::Instance()->GetDefaultFontEngine();00050 }00051 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ScrollbarRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00052 ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00053 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a> = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CScrollBar.html">CScrollBar</a>(00054 <a class="code" href="classwGui_1_1CRect.html">CRect</a>(ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - 12, ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>()) , <span class="keyword">this</span>, CScrollBar::VERTICAL),00055 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a2">SetLimits</a>(0, 0);00056 <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(2, 2, <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 16, <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - 4);00057 <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = COLOR_WHITE;00058 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::KEYBOARD_KEYDOWN);00059 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_VALUECHANGE);00060 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_VALUECHANGING);00061 }00062 00063 <a name="l00064"></a><a class="code" href="classwGui_1_1CListBox.html#a1">00064</a> CListBox::~CListBox(<span class="keywordtype">void</span>)00065 {00066 <span class="keyword">delete</span> <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>;00067 }00068 00069 <a name="l00070"></a><a class="code" href="classwGui_1_1CListBox.html#a3">00070</a> <span class="keywordtype">void</span> CListBox::SetItemHeight(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iItemHeight)00071 {00072 <a class="code" href="classwGui_1_1CListBox.html#n2">m_iItemHeight</a> = iItemHeight;00073 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00074 }00075 00076 <a name="l00077"></a><a class="code" href="classwGui_1_1CListBox.html#a4">00077</a> <span class="keywordtype">int</span> CListBox::AddItem(<a class="code" href="structwGui_1_1SListItem.html">SListItem</a> ListItem)00078 {00079 <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.push_back(ListItem);00080 <a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>.push_back(<span class="keyword">false</span>);00081 <a class="code" href="classwGui_1_1CListBox.html#n6">m_RenderedStrings</a>.push_back(<a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(<a class="code" href="classwGui_1_1CListBox.html#n0">m_pFontEngine</a>, ListItem.<a class="code" href="structwGui_1_1SListItem.html#m0">sItemText</a>, CRenderedString::VALIGN_TOP, CRenderedString::HALIGN_LEFT));00082 <span class="keywordtype">int</span> iMax = (<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size() - 1) < 0 ? 0 : static_cast<int>(<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size() - 1);00083 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a2">SetLimits</a>(0, iMax);00084 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00085 <span class="keywordflow">return</span> static_cast<int>(<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size());00086 }00087 00088 <a name="l00089"></a><a class="code" href="classwGui_1_1CListBox.html#a6">00089</a> <span class="keywordtype">void</span> CListBox::RemoveItem(<span class="keywordtype">int</span> iItemIndex)00090 {00091 <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.erase(<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.begin() + iItemIndex);00092 <a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>.erase(<a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>.begin() + iItemIndex);00093 <span class="keywordtype">int</span> iMax = (<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size() - 1) < 0 ? 0 : static_cast<int>(<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size() - 1);00094 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a2">SetLimits</a>(0, iMax);00095 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00096 }00097 00098 <a name="l00099"></a><a class="code" href="classwGui_1_1CListBox.html#a7">00099</a> <span class="keywordtype">void</span> CListBox::ClearItems(<span class="keywordtype">void</span>)00100 {00101 <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.clear();00102 <a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>.clear();00103 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a2">SetLimits</a>(0, 0);00104 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00105 }00106 <a name="l00107"></a><a class="code" href="classwGui_1_1CListBox.html#a11">00107</a> <span class="keywordtype">void</span> CListBox::SetAllSelections(<span class="keywordtype">bool</span> bSelected)00108 {00109 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size(); ++i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -