📄 wg__listbox_8cpp-source.html
字号:
00110 {00111 <a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>[i] = bSelected;00112 }00113 }00114 00115 <a name="l00116"></a><a class="code" href="classwGui_1_1CListBox.html#a13">00116</a> <span class="keywordtype">void</span> CListBox::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00117 <span class="keyword"></span>{00118 CWindow::Draw();00119 00120 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00121 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>, <span class="keyword">false</span>, COLOR_BLACK);00122 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ClientRect(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00123 <span class="keywordtype">int</span> iStartIndex = <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a6">GetPosition</a>();00124 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = iStartIndex; i < <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.size(); ++i)00125 {00126 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ItemRect(ClientRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), ClientRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + (i - iStartIndex) * <a class="code" href="classwGui_1_1CListBox.html#n2">m_iItemHeight</a>,00127 ClientRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), ClientRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + (i - iStartIndex + 1) * <a class="code" href="classwGui_1_1CListBox.html#n2">m_iItemHeight</a> - 1);00128 <span class="keywordflow">if</span> (ItemRect.<a class="code" href="classwGui_1_1CRect.html#a30">Overlaps</a>(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>()))00129 {00130 ItemRect.<a class="code" href="classwGui_1_1CRect.html#a31">ClipTo</a>(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00131 ItemRect.<a class="code" href="classwGui_1_1CRect.html#a8">SetBottom</a>(ItemRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>() - 1);00132 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CListBox.html#n5">m_SelectedItems</a>[i])00133 {00134 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(ItemRect, <span class="keyword">true</span>, COLOR_LIGHTGRAY, COLOR_LIGHTGRAY);00135 }00136 <span class="keywordflow">if</span> (static_cast<int>(i) == <a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a>)00137 {00138 ItemRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(1);00139 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(ItemRect, <span class="keyword">false</span>, COLOR_BLACK);00140 ItemRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00141 }00142 ItemRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00143 <a class="code" href="classwGui_1_1CListBox.html#n6">m_RenderedStrings</a>[i].Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, ItemRect, ItemRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(0, 1), <a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>[i].ItemColor);00144 }00145 }00146 }00147 00148 <a name="l00149"></a><a class="code" href="classwGui_1_1CListBox.html#a14">00149</a> <span class="keywordtype">void</span> CListBox::SetWindowRect(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& WindowRect)00150 {00151 CWindow::SetWindowRect(WindowRect);00152 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ScrollbarRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00153 ScrollbarRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00154 <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a8">SetWindowRect</a>(<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>()));00155 <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);00156 }00157 00158 <a name="l00159"></a><a class="code" href="classwGui_1_1CListBox.html#a15">00159</a> <span class="keywordtype">bool</span> CListBox::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00160 {00161 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00162 00163 <span class="keywordflow">if</span> (! CWindow::OnMouseButtonDown(Point, Button) && <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE) &&00164 (Button == CMouseMessage::LEFT))00165 {00166 <span class="keywordflow">if</span> (CApplication::Instance()->GetKeyFocus() != <span class="keyword">this</span>)00167 {00168 CApplication::Instance()->SetKeyFocus(<span class="keyword">this</span>);00169 }00170 00171 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ClientRect(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00172 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CListBox.html#n4">m_Items</a>.empty() && ClientRect.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE)00173 {00174 <span class="comment">// Prep the new selection</span>00175 <a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a> = (Point.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>() - ClientRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>()) / <a class="code" href="classwGui_1_1CListBox.html#n2">m_iItemHeight</a> + <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a6">GetPosition</a>();00176 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00177 }00178 bResult = <span class="keyword">true</span>;00179 }00180 00181 <span class="keywordflow">return</span> bResult;00182 }00183 00184 <a name="l00185"></a><a class="code" href="classwGui_1_1CListBox.html#a16">00185</a> <span class="keywordtype">bool</span> CListBox::OnMouseButtonUp(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00186 {00187 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00188 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ClientRect(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00189 00190 <span class="keywordflow">if</span> (! CWindow::OnMouseButtonUp(Point, Button) && <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && (ClientRect.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE) &&00191 (Button == CMouseMessage::LEFT))00192 {00193 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a> == static_cast<int>((Point.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>() - ClientRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>()) / <a class="code" href="classwGui_1_1CListBox.html#n2">m_iItemHeight</a> + <a class="code" href="classwGui_1_1CListBox.html#n1">m_pVScrollbar</a>-><a class="code" href="classwGui_1_1CScrollBar.html#a6">GetPosition</a>()))00194 {00195 <span class="keywordflow">if</span> (m_bSingleSelection)00196 {00197 <a class="code" href="classwGui_1_1CListBox.html#a11">SetAllSelections</a>(<span class="keyword">false</span>);00198 }00199 <a class="code" href="classwGui_1_1CListBox.html#a10">SetSelection</a>(<a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a>, ! <a class="code" href="classwGui_1_1CListBox.html#a9">IsSelected</a>(<a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a>));00200 <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pDestination = <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>;00201 <span class="keywordflow">if</span> (m_pDropDown)00202 {00203 pDestination = <a class="code" href="classwGui_1_1CListBox.html#n8">m_pDropDown</a>;00204 }00205 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_VALUECHANGE, pDestination, <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CListBox.html#n3">m_iFocusedItem</a>));00206 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00207 }00208 bResult = <span class="keyword">true</span>;00209 }00210 00211 <span class="keywordflow">return</span> bResult;00212 }00213 00214 <a name="l00215"></a><a class="code" href="classwGui_1_1CListBox.html#a17">00215</a> <span class="keywordtype">bool</span> CListBox::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00216 {00217 <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00218 00219 <span class="keywordflow">if</span> (pMessage)00220 {00221 <span class="keywordflow">switch</span>(pMessage-><a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00222 {00223 <span class="keywordflow">case</span> CMessage::KEYBOARD_KEYDOWN:00224 {00225 <a class="code" href="classwGui_1_1CKeyboardMessage.html">CKeyboardMessage</a>* pKeyMsg = dynamic_cast<CKeyboardMessage*>(pMessage);00226 <span class="keywordflow">if</span> (pKeyMsg && pMessage-><a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -