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

📄 wg__window_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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_window.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_window.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_window.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CWindow 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_window.h"</span>00027 <span class="preprocessor">#include "std_ex.h"</span>00028 <span class="preprocessor">#include "wg_painter.h"</span>00029 <span class="preprocessor">#include "wg_application.h"</span>00030 <span class="preprocessor">#include "wg_error.h"</span>00031 <span class="preprocessor">#include "wg_debug.h"</span>00032 <span class="preprocessor">#include "wg_message_server.h"</span>00033 <span class="preprocessor">#include &lt;algorithm&gt;</span>00034 00035 00036 <span class="keyword">namespace </span>wGui00037 {00038 <a name="l00039"></a><a class="code" href="classwGui_1_1CWindow.html#a0">00039</a> CWindow::CWindow(<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) :00040      m_sWindowText(""),00041      m_WindowRect(WindowRect),00042      m_BGColor(DEFAULT_BG_COLOR),00043      m_ClientRect(0, 0, WindowRect.Width() - 1, WindowRect.Height() - 1),00044      m_pParentWindow(0),00045      m_pSDLSurface(0),00046      m_bVisible(true),00047      m_sClassName("<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>")00048 {00049      <span class="keywordflow">if</span> (!CApplication::Instance())00050      {00051           <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CWindow Constructor: No Application instance!"</span>));00052      }00053 00054      <a class="code" href="classwGui_1_1CWindow.html#a24">SetNewParent</a>(pParent);00055      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::APP_PAINT);00056 }00057 00058 <a name="l00059"></a><a class="code" href="classwGui_1_1CWindow.html#a1">00059</a> CWindow::~CWindow(<span class="keywordtype">void</span>)00060 {00061      <span class="comment">// Each child window is deleted, and should in their destructors call back to this object to Deregister themselves</span>00062      CMessageServer::Instance().DeregisterMessageClient(<span class="keyword">this</span>);00063 00064      <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iSanityCheck = static_cast&lt;unsigned int&gt;(<a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.size());00065      <span class="keywordflow">while</span> (<a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.size() &gt; 0 &amp;&amp; iSanityCheck &gt; 0)00066      {00067           <span class="keyword">delete</span> *(<a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.begin());00068           --iSanityCheck;00069      }00070      TraceIf(iSanityCheck != 0, <span class="stringliteral">"Sanity check failed in CWindow:"</span> + <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> + <span class="stringliteral">" destructor!  Sanity is: "</span> + stdex::itoa(iSanityCheck));00071      TraceIf(!<a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.empty(), <span class="stringliteral">"CWindow:"</span> + <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> + <span class="stringliteral">" children not empty at end of destructor!"</span>);00072      <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.clear();00073      <a class="code" href="classwGui_1_1CWindow.html#a24">SetNewParent</a>(0);00074 }00075 00076 <a name="l00077"></a><a class="code" href="classwGui_1_1CWindow.html#a2">00077</a> <span class="keywordtype">void</span> CWindow::SetWindowRect(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect)00078 {00079      <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a> = WindowRect;00080      CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, <a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s0">PARENT</a>), <span class="keyword">this</span>));00081 }00082 00083 <a name="l00084"></a><a class="code" href="classwGui_1_1CWindow.html#a4">00084</a> <span class="keywordtype">void</span> CWindow::MoveWindow(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>&amp; MoveDistance)00085 {00086      <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a> = <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a> + MoveDistance;00087      <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> + MoveDistance;00088      <span class="keywordflow">for</span> (std::list&lt;CWindow*&gt;::iterator iter = <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.begin(); iter != <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.end(); ++iter)00089      {00090           (*iter)-&gt;MoveWindow(MoveDistance);00091      }00092      CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, <a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s0">PARENT</a>), <span class="keyword">this</span>));00093 }00094 00095 <a name="l00096"></a><a class="code" href="classwGui_1_1CWindow.html#a5">00096</a> <a class="code" href="classwGui_1_1CRect.html">CRect</a> CWindow::GetClientRect(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00097 <span class="keyword"></span>{00098      <a class="code" href="classwGui_1_1CRect.html">CRect</a> ClientRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>() + <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a>.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>() + <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a>.<a class="code" href="classwGui_1_1CRect.html#a16">BottomRight</a>());00099      ClientRect.<a class="code" href="classwGui_1_1CRect.html#a31">ClipTo</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00100      <span class="keywordflow">return</span> ClientRect;00101 }00102 00103 <a name="l00104"></a><a class="code" href="classwGui_1_1CWindow.html#a8">00104</a> <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* CWindow::GetAncestor(EAncestor eAncestor)<span class="keyword"> const</span>00105 <span class="keyword"></span>{00106      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pWindow = 0;00107 00108      <span class="keywordflow">switch</span> (eAncestor)00109      {00110      <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CWindow.html#s2s0">PARENT</a>:00111           pWindow = <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>;00112           <span class="keywordflow">break</span>;00113      <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CWindow.html#s2s1">ROOT</a>:00114           pWindow = <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>;00115           <span class="keywordflow">if</span> (pWindow)00116           {00117                <span class="keywordflow">while</span> (pWindow-&gt;<a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>)00118                {00119                     pWindow = pWindow-&gt;<a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>;00120                }00121           }00122           <span class="keywordflow">else</span>00123           {00124                pWindow = const_cast&lt;CWindow*&gt;(this);00125           }00126           <span class="keywordflow">break</span>;00127      }00128 00129      <span class="keywordflow">return</span> pWindow;00130 }00131 00132 <a name="l00133"></a><a class="code" href="classwGui_1_1CWindow.html#a9">00133</a> <span class="keywordtype">bool</span> CWindow::IsChildOf(<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pWindow)<span class="keyword"> const</span>00134 <span class="keyword"></span>{00135      <span class="keyword">const</span> <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pCurrentWindow = <span class="keyword">this</span>;00136      <span class="keywordtype">bool</span> bIsChild = <span class="keyword">false</span>;00137 00138      <span class="keywordflow">while</span> (!bIsChild &amp;&amp; pCurrentWindow)00139      {00140           pCurrentWindow = pCurrentWindow-&gt;<a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s0">PARENT</a>);00141           <span class="keywordflow">if</span> (pCurrentWindow == pWindow)00142           {00143                bIsChild = <span class="keyword">true</span>;00144           }00145      }00146 00147      <span class="keywordflow">return</span> bIsChild;00148 }00149 00150 <a name="l00151"></a><a class="code" href="classwGui_1_1CWindow.html#a11">00151</a> <span class="keywordtype">void</span> CWindow::SetVisible(<span class="keywordtype">bool</span> bVisible)00152 {00153      <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> = bVisible;00154      <span class="keywordflow">for</span> (std::list&lt;CWindow*&gt;::const_iterator iter = <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.begin(); iter != <a class="code" href="classwGui_1_1CWindow.html#n5">m_ChildWindows</a>.end(); ++iter)00155      {00156           (*iter)-&gt;SetVisible(bVisible);00157           <span class="keywordflow">if</span> ((*iter) == CApplication::Instance()-&gt;GetKeyFocus())

⌨️ 快捷键说明

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