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

📄 wg__toolbar_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_toolbar.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_toolbar.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_toolbar.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CToolBar 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_toolbar.h"</span>00027 <span class="preprocessor">#include "wg_message_server.h"</span>00028 <span class="preprocessor">#include "wg_debug.h"</span>00029 00030 00031 <span class="keyword">namespace </span>wGui00032 {00033 <a name="l00034"></a><a class="code" href="classwGui_1_1CToolBar.html#a0">00034</a> CToolBar::CToolBar(<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) :00035      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent)00036 {00037   <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CToolBar"</span>;00038      <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = COLOR_LIGHTGRAY;00039      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_LCLICK);00040 }00041 00042 <a name="l00043"></a><a class="code" href="classwGui_1_1CToolBar.html#a1">00043</a> CToolBar::~CToolBar(<span class="keywordtype">void</span>)00044 {00045 00046 }00047 00048 <a name="l00049"></a><a class="code" href="classwGui_1_1CToolBar.html#a2">00049</a> <span class="keywordtype">void</span> CToolBar::InsertButton(<a class="code" href="classwGui_1_1CButton.html">CButton</a>* pButton, <span class="keywordtype">long</span> <span class="keywordtype">int</span> iButtonID, <span class="keywordtype">int</span> iPosition)00050 {00051      <span class="keywordtype">long</span> <span class="keywordtype">int</span> iFixedButtonID = iButtonID;00052      <span class="keywordflow">if</span> (pButton == 0)00053      {00054           iFixedButtonID = 0;00055      }00056      <span class="keywordflow">else</span>00057      {00058           <span class="comment">// Transfer ownership of the button to the ToolBar</span>00059           pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a24">SetNewParent</a>(<span class="keyword">this</span>);00060      }00061      <span class="keywordflow">if</span> (iPosition == -1)00062      {00063           <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.push_back(std::make_pair(pButton, iFixedButtonID));00064      }00065      <span class="keywordflow">else</span>00066      {00067           <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.insert(<a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.begin() + iPosition, std::make_pair(pButton, iFixedButtonID));00068      }00069      <a class="code" href="classwGui_1_1CToolBar.html#b0">RepositionButtons</a>();00070 }00071 00072 <a name="l00073"></a><a class="code" href="classwGui_1_1CToolBar.html#a3">00073</a> <span class="keywordtype">void</span> CToolBar::RemoveButton(<span class="keywordtype">int</span> iPosition)00074 {00075      <a class="code" href="classwGui_1_1CButton.html">CButton</a>* pButton = <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.at(iPosition).first;00076      <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.erase(<a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.begin() + iPosition);00077      <span class="keyword">delete</span> pButton;00078 }00079 00080 <a name="l00081"></a><a class="code" href="classwGui_1_1CToolBar.html#a6">00081</a> <span class="keywordtype">int</span> CToolBar::GetButtonPosition(<span class="keywordtype">long</span> <span class="keywordtype">int</span> iButtonID)00082 {00083      <span class="keywordtype">int</span> iPosition = -1;00084      <span class="keywordflow">for</span> (t_ButtonVector::iterator iter = <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.begin(); iter != <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.end(); ++iter)00085      {00086           ++iPosition;00087           <span class="keywordflow">if</span> (iter-&gt;second == iButtonID)00088           {00089                <span class="keywordflow">return</span> iPosition;00090           }00091      }00092      <span class="keywordflow">return</span> -1;00093 }00094 00095 <a name="l00096"></a><a class="code" href="classwGui_1_1CToolBar.html#b0">00096</a> <span class="keywordtype">void</span> CToolBar::RepositionButtons(<span class="keywordtype">void</span>)00097 {00098      <span class="keywordtype">int</span> xPosition = <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + 4;00099      <span class="keywordflow">for</span> (t_ButtonVector::iterator iter = <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.begin(); iter != <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.end(); ++iter)00100      {00101           <a class="code" href="classwGui_1_1CButton.html">CButton</a>* pButton = iter-&gt;first;00102           <span class="keywordflow">if</span> (pButton)00103           {00104                <span class="keywordtype">int</span> xStartPosition = xPosition;00105                xPosition = xPosition + 2 + pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>();00106                pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a2">SetWindowRect</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(xStartPosition, <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + 2, xPosition - 3,00107                     <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + 1 + pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()));00108 00109                <span class="comment">// Hide any buttons that extend beyond the end of the toolbar</span>00110                <span class="keywordflow">if</span> (xPosition &gt; <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>())00111                {00112                     pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a11">SetVisible</a>(<span class="keyword">false</span>);00113                }00114                <span class="keywordflow">else</span>00115                {00116                     pButton-&gt;<a class="code" href="classwGui_1_1CWindow.html#a11">SetVisible</a>(<span class="keyword">true</span>);00117                }00118           }00119           <span class="keywordflow">else</span>00120           {00121                <span class="comment">// Spacer</span>00122                xPosition += 6;00123           }00124      }00125 }00126 00127 <a name="l00128"></a><a class="code" href="classwGui_1_1CToolBar.html#a7">00128</a> <span class="keywordtype">void</span> CToolBar::SetWindowRect(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect)00129 {00130      CWindow::SetWindowRect(WindowRect);00131      <a class="code" href="classwGui_1_1CToolBar.html#b0">RepositionButtons</a>();00132 }00133 00134 <a name="l00135"></a><a class="code" href="classwGui_1_1CToolBar.html#a8">00135</a> <span class="keywordtype">bool</span> CToolBar::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00136 {00137      <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00138 00139      <span class="keywordflow">if</span> (pMessage)00140      {00141           <span class="keywordflow">switch</span>(pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00142           {00143           <span class="keywordflow">case</span> CMessage::CTRL_LCLICK:00144           {00145                <span class="keywordflow">if</span> (pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)00146                {00147                     <span class="keywordtype">long</span> <span class="keywordtype">int</span> iButtonID = 0;00148                     <span class="keywordflow">for</span> (t_ButtonVector::iterator iter = <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.begin(); iter != <a class="code" href="classwGui_1_1CToolBar.html#n0">m_vpButtons</a>.end(); ++iter)00149                     {00150                          <span class="keywordflow">if</span> (iter-&gt;first == pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a4">Source</a>())00151                          {00152                               iButtonID = iter-&gt;second;00153                          }00154                     }00155                     CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_LCLICK, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>, <span class="keyword">this</span>, iButtonID));00156                     bHandled = <span class="keyword">true</span>;00157                }00158                <span class="keywordflow">break</span>;00159           }00160           <span class="keywordflow">default</span> :00161                bHandled = CWindow::HandleMessage(pMessage);00162                <span class="keywordflow">break</span>;00163           }00164      }00165 00166      <span class="keywordflow">return</span> bHandled;00167 }00168 00169 }00170 </pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:25 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 + -