⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wg__checkbox_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 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_checkbox.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> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; </center><hr><h1>wg_checkbox.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_checkbox.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CCheckBox 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_checkbox.h"</span>00027 <span class="preprocessor">#include "wg_message_server.h"</span>00028 00029 00030 <span class="keyword">namespace </span>wGui00031 {00032 <a name="l00033"></a><a class="code" href="classwGui_1_1CCheckBox.html#a0">00033</a> CCheckBox::CCheckBox(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect, <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pParent) :00034      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00035      m_eCheckBoxState(UNCHECKED),00036      m_MouseButton(0)00037 {00038   <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CCheckBox"</span>;00039      <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = COLOR_WHITE;00040      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONUP);00041      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_LCLICK);00042 }00043 00044 <a name="l00045"></a><a class="code" href="classwGui_1_1CCheckBox.html#a1">00045</a> CCheckBox::~CCheckBox(<span class="keywordtype">void</span>)00046 {00047 00048 }00049 00050 <a name="l00051"></a><a class="code" href="classwGui_1_1CCheckBox.html#a3">00051</a> <span class="keywordtype">void</span> CCheckBox::SetCheckBoxState(EState eState)00052 {00053      <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> != eState)00054      {00055           <a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> = eState;00056           <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00057      }00058 }00059 00060 <a name="l00061"></a><a class="code" href="classwGui_1_1CCheckBox.html#a4">00061</a> <span class="keywordtype">void</span> CCheckBox::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00062 <span class="keyword"></span>{00063      CWindow::Draw();00064 00065      <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00066      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00067      <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00068      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);00069      <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> != <a class="code" href="classwGui_1_1CCheckBox.html#s3s2">DISABLED</a>)00070      {00071           Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00072           Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), COLOR_DARKGRAY);00073           Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), COLOR_DARKGRAY);00074           SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00075           <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> == <a class="code" href="classwGui_1_1CCheckBox.html#s3s1">CHECKED</a>)00076           {00077                Painter.<a class="code" href="classwGui_1_1CPainter.html#a6">DrawLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a16">BottomRight</a>(), DEFAULT_LINE_COLOR);00078                Painter.<a class="code" href="classwGui_1_1CPainter.html#a6">DrawLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a15">BottomLeft</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a14">TopRight</a>(), DEFAULT_LINE_COLOR);00079           }00080      }00081 }00082 00083 <a name="l00084"></a><a class="code" href="classwGui_1_1CCheckBox.html#a5">00084</a> <span class="keywordtype">bool</span> CCheckBox::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00085 {00086      <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00087 00088      <span class="keywordflow">if</span> (! CWindow::OnMouseButtonDown(Point, Button) &amp;&amp; <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> &amp;&amp; (<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) &amp;&amp;00089           (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> != <a class="code" href="classwGui_1_1CCheckBox.html#s3s2">DISABLED</a>))00090      {00091           <a class="code" href="classwGui_1_1CCheckBox.html#n1">m_MouseButton</a> = Button;00092           bResult = <span class="keyword">true</span>;00093      }00094 00095      <span class="keywordflow">return</span> bResult;00096 }00097 00098 <a name="l00099"></a><a class="code" href="classwGui_1_1CCheckBox.html#a6">00099</a> <span class="keywordtype">bool</span> CCheckBox::OnMouseButtonUp(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00100 {00101      <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00102 00103      <span class="keywordflow">if</span> (! CWindow::OnMouseButtonUp(Point, Button) &amp;&amp; <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> &amp;&amp; (<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) &amp;&amp;00104           (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> != <a class="code" href="classwGui_1_1CCheckBox.html#s3s2">DISABLED</a>) &amp;&amp; (<a class="code" href="classwGui_1_1CCheckBox.html#n1">m_MouseButton</a> == Button))00105      {00106           CMessage::EMessageType MessageType =  CMessage::UNKNOWN;00107           <span class="keywordflow">switch</span> (m_MouseButton)00108           {00109           <span class="keywordflow">case</span> CMouseMessage::LEFT:00110                MessageType = CMessage::CTRL_LCLICK;00111                <span class="keywordflow">break</span>;00112           <span class="keywordflow">case</span> CMouseMessage::RIGHT:00113                MessageType = CMessage::CTRL_RCLICK;00114                <span class="keywordflow">break</span>;00115           <span class="keywordflow">case</span> CMouseMessage::MIDDLE:00116                MessageType = CMessage::CTRL_MCLICK;00117                <span class="keywordflow">break</span>;00118           }00119           CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(MessageType, <span class="keyword">this</span>, <span class="keyword">this</span>, 0));00120           bResult = <span class="keyword">true</span>;00121      }00122 00123      <span class="keywordflow">return</span> bResult;00124 }00125 00126 <a name="l00127"></a><a class="code" href="classwGui_1_1CCheckBox.html#a7">00127</a> <span class="keywordtype">bool</span> CCheckBox::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00128 {00129      <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00130 00131      <span class="keywordflow">if</span> (pMessage)00132      {00133           <span class="keywordflow">switch</span>(pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00134           {00135           <span class="keywordflow">case</span> CMessage::MOUSE_BUTTONUP:00136           {00137                <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast&lt;CMouseMessage*&gt;(pMessage);00138                <span class="keywordflow">if</span> (pMouseMessage &amp;&amp; (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(pMouseMessage-&gt;<a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) != CRect::RELPOS_INSIDE)00139                     &amp;&amp; (<a class="code" href="classwGui_1_1CCheckBox.html#n1">m_MouseButton</a> == pMouseMessage-&gt;<a class="code" href="classwGui_1_1CMouseMessage.html#m2">Button</a>) &amp;&amp; (<a class="code" href="classwGui_1_1CCheckBox.html#n0">m_eCheckBoxState</a> != <a class="code" href="classwGui_1_1CCheckBox.html#s3s2">DISABLED</a>))00140                {00141                     <a class="code" href="classwGui_1_1CCheckBox.html#n1">m_MouseButton</a> = 0;00142                     bHandled = <span class="keyword">true</span>;00143                }00144                <span class="keywordflow">break</span>;00145           }00146           <span class="keywordflow">case</span> CMessage::CTRL_LCLICK:00147                <span class="keywordflow">if</span> (pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)00148                {00149                     <span class="keywordflow">switch</span> (m_eCheckBoxState)00150                     {00151                     <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CCheckBox.html#s3s0">UNCHECKED</a>:00152                          <a class="code" href="classwGui_1_1CCheckBox.html#a3">SetCheckBoxState</a>(<a class="code" href="classwGui_1_1CCheckBox.html#s3s1">CHECKED</a>);00153                          CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_VALUECHANGE, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>, <span class="keyword">this</span>, 1));00154                          <span class="keywordflow">break</span>;00155                     <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CCheckBox.html#s3s1">CHECKED</a>:00156                          <a class="code" href="classwGui_1_1CCheckBox.html#a3">SetCheckBoxState</a>(<a class="code" href="classwGui_1_1CCheckBox.html#s3s0">UNCHECKED</a>);00157                          CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_VALUECHANGE, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>, <span class="keyword">this</span>, 0));00158                          <span class="keywordflow">break</span>;00159                     <span class="keywordflow">default</span>:00160                          <span class="keywordflow">break</span>;00161                     }00162                     bHandled = <span class="keyword">true</span>;00163                }00164                <span class="keywordflow">break</span>;00165           <span class="keywordflow">default</span> :00166                bHandled = CWindow::HandleMessage(pMessage);00167                <span class="keywordflow">break</span>;00168           }00169      }00170 00171      <span class="keywordflow">return</span> bHandled;00172 }00173 00174 }00175 00176 00177 </pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:22 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -