📄 wg__menu_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_menu.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_menu.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_menu.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CMenu 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_menu.h"</span>00027 <span class="preprocessor">#include "std_ex.h"</span>00028 <span class="preprocessor">#include "wg_application.h"</span>00029 <span class="preprocessor">#include "wg_message_server.h"</span>00030 <span class="preprocessor">#include "wg_debug.h"</span>00031 <span class="preprocessor">#include "wg_error.h"</span>00032 00033 00034 <span class="keyword">namespace </span>wGui00035 {00036 00037 <span class="comment">// CMenuBase</span>00038 <a name="l00039"></a><a class="code" href="classwGui_1_1CMenuBase.html#a0">00039</a> CMenuBase::CMenuBase(<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, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine) :00040 <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00041 m_pHighlightedItem(0),00042 m_bCachedRectsValid(false),00043 m_pActivePopup(0),00044 m_hRightArrowBitmap(WGRES_RIGHT_ARROW_BITMAP),00045 m_HighlightColor(COLOR_DARKGRAY)00046 {00047 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CMenuBase"</span>;00048 <span class="keywordflow">if</span> (pFontEngine)00049 {00050 <a class="code" href="classwGui_1_1CMenuBase.html#n0">m_pFontEngine</a> = pFontEngine;00051 }00052 <span class="keywordflow">else</span>00053 {00054 <a class="code" href="classwGui_1_1CMenuBase.html#n0">m_pFontEngine</a> = CApplication::Instance()->GetDefaultFontEngine();00055 }00056 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00057 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_LCLICK);00058 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_TIMER);00059 00060 <a class="code" href="classwGui_1_1CMenuBase.html#n7">m_pPopupTimer</a> = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CTimer.html">CTimer</a>(<span class="keyword">this</span>);00061 }00062 00063 <a name="l00064"></a><a class="code" href="classwGui_1_1CMenuBase.html#a1">00064</a> CMenuBase::~CMenuBase(<span class="keywordtype">void</span>)00065 {00066 00067 }00068 00069 <a name="l00070"></a><a class="code" href="classwGui_1_1CMenuBase.html#a2">00070</a> <span class="keywordtype">void</span> CMenuBase::InsertMenuItem(<span class="keyword">const</span> <a class="code" href="structwGui_1_1SMenuItem.html">SMenuItem</a>& MenuItem, <span class="keywordtype">int</span> iPosition)00071 {00072 <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.insert((iPosition == -1) ? <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end() : <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin() + iPosition,00073 std::make_pair(MenuItem, std::make_pair(<a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(<a class="code" href="classwGui_1_1CMenuBase.html#n0">m_pFontEngine</a>, MenuItem.<a class="code" href="structwGui_1_1SMenuItem.html#m0">sItemText</a>, CRenderedString::VALIGN_TOP), <a class="code" href="classwGui_1_1CRect.html">CRect</a>())));00074 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">false</span>;00075 }00076 00077 <a name="l00078"></a><a class="code" href="classwGui_1_1CMenuBase.html#a3">00078</a> <span class="keywordtype">void</span> CMenuBase::RemoveMenuItem(<span class="keywordtype">int</span> iPosition)00079 {00080 <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.erase(<a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin() + iPosition);00081 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">false</span>;00082 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00083 }00084 00085 <a name="l00086"></a><a class="code" href="classwGui_1_1CMenuBase.html#a5">00086</a> <span class="keywordtype">void</span> CMenuBase::HideActivePopup(<span class="keywordtype">void</span>)00087 {00088 <span class="keywordflow">if</span> (m_pActivePopup)00089 {00090 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CPopupMenu.html#a3">Hide</a>();00091 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a> = 0;00092 }00093 }00094 00095 <a name="l00096"></a><a class="code" href="classwGui_1_1CMenuBase.html#a8">00096</a> <span class="keywordtype">bool</span> CMenuBase::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00097 {00098 <span class="comment">// We cant do quite the same thing as normal since children of menus don't appear inside their bounds</span>00099 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00100 00101 <span class="keywordflow">if</span> (m_bVisible)00102 {00103 <span class="keywordflow">for</span> (std::list<CWindow*>::reverse_iterator iter = <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.rbegin(); iter != <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.rend(); ++iter)00104 {00105 bResult = (*iter)->OnMouseButtonDown(Point, Button);00106 <span class="keywordflow">if</span> (bResult)00107 {00108 <span class="keywordflow">break</span>;00109 }00110 }00111 }00112 00113 <span class="keywordflow">return</span> bResult;00114 }00115 00116 <a name="l00117"></a><a class="code" href="classwGui_1_1CMenuBase.html#a9">00117</a> <span class="keywordtype">bool</span> CMenuBase::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00118 {00119 <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00120 00121 <span class="keywordflow">if</span> (pMessage)00122 {00123 <span class="keywordflow">switch</span>(pMessage-><a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00124 {00125 <span class="keywordflow">case</span> CMessage::MOUSE_MOVE:00126 {00127 <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);00128 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && pMouseMessage && <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(pMouseMessage-><a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) == CRect::RELPOS_INSIDE)00129 {00130 <a class="code" href="classwGui_1_1CMenuBase.html#b0">UpdateCachedRects</a>();00131 <a class="code" href="structwGui_1_1SMenuItem.html">SMenuItem</a>* pOldHighlight = <a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a>;00132 m_pHighlightedItem = 0;00133 <span class="keywordflow">for</span> (t_MenuItemVector::iterator iter = <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin(); iter != <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end(); ++iter)00134 {00135 <span class="keywordflow">if</span> (iter->second.second.HitTest(pMouseMessage-><a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) == CRect::RELPOS_INSIDE && !iter->first.bSpacer)00136 {00137 <span class="keywordflow">if</span> (m_pHighlightedItem != &(iter->first))00138 {00139 <a class="code" href="classwGui_1_1CMenuBase.html#n7">m_pPopupTimer</a>-><a class="code" href="classwGui_1_1CTimer.html#a3">StopTimer</a>();00140 m_pHighlightedItem = &(iter->first);00141 <span class="keywordflow">if</span> (iter->first.pPopup)00142 {00143 <a class="code" href="classwGui_1_1CMenuBase.html#n7">m_pPopupTimer</a>-><a class="code" href="classwGui_1_1CTimer.html#a2">StartTimer</a>(1000);00144 }00145 }00146 <span class="keywordflow">break</span>;00147 }00148 }00149 <span class="keywordflow">if</span> (pOldHighlight != m_pHighlightedItem)00150 {00151 TraceIf(m_pHighlightedItem != 0, <span class="stringliteral">"Menu Highlight Item Changed to : "</span> + (m_pHighlightedItem ? m_pHighlightedItem-><a class="code" href="structwGui_1_1SMenuItem.html#m0">sItemText</a> : std::string(<span class="stringliteral">""</span>)));00152 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00153 }00154 }00155 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> != 0)00156 {00157 <a class="code" href="classwGui_1_1CMenuBase.html#n7">m_pPopupTimer</a>-><a class="code" href="classwGui_1_1CTimer.html#a3">StopTimer</a>();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -