📄 wg__editbox_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_editbox.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_editbox.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_editbox.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CEditBox 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_editbox.h"</span>00027 <span class="preprocessor">#include "wg_message_server.h"</span>00028 <span class="preprocessor">#include "wg_application.h"</span>00029 <span class="preprocessor">#include "wg_error.h"</span>00030 <span class="preprocessor">#include "wg_debug.h"</span>00031 <span class="preprocessor">#include <string></span>00032 00033 <span class="keyword">namespace </span>wGui00034 {00035 <a name="l00036"></a><a class="code" href="classwGui_1_1CEditBox.html#a0">00036</a> CEditBox::CEditBox(<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) :00037 <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00038 m_SelStart(0),00039 m_SelLength(0),00040 m_DragStart(0),00041 m_ScrollOffset(0),00042 m_bReadOnly(false),00043 m_bMouseDown(false),00044 m_bUseMask(false),00045 m_bLastMouseMoveInside(false)00046 {00047 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CEditBox"</span>;00048 <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = COLOR_WHITE;00049 <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a>.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-4);00050 <span class="keywordflow">if</span> (pFontEngine)00051 {00052 <a class="code" href="classwGui_1_1CEditBox.html#n0">m_pFontEngine</a> = pFontEngine;00053 }00054 <span class="keywordflow">else</span>00055 {00056 <a class="code" href="classwGui_1_1CEditBox.html#n0">m_pFontEngine</a> = CApplication::Instance()->GetDefaultFontEngine();00057 }00058 std::auto_ptr<CRenderedString> pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(00059 <a class="code" href="classwGui_1_1CEditBox.html#n0">m_pFontEngine</a>, <span class="stringliteral">""</span>, CRenderedString::VALIGN_NORMAL, CRenderedString::HALIGN_LEFT));00060 <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a> = pRenderedString;00061 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::KEYBOARD_KEYDOWN);00062 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONUP);00063 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00064 }00065 00066 <a name="l00067"></a><a class="code" href="classwGui_1_1CEditBox.html#a4">00067</a> <span class="keywordtype">void</span> CEditBox::SetReadOnly(<span class="keywordtype">bool</span> bReadOnly)00068 {00069 <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = bReadOnly ? COLOR_LIGHTGRAY : COLOR_WHITE;00070 <a class="code" href="classwGui_1_1CEditBox.html#n7">m_bReadOnly</a> = bReadOnly;00071 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00072 }00073 00074 <a name="l00075"></a><a class="code" href="classwGui_1_1CEditBox.html#a6">00075</a> std::string CEditBox::GetSelText(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00076 <span class="keyword"></span>{00077 <span class="keywordflow">if</span> (m_bUseMask)00078 {00079 <span class="keywordflow">return</span> <span class="stringliteral">""</span>;00080 }00081 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> != 0)00082 {00083 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> SelStartNorm=0, SelLenNorm=0;00084 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> < 0)00085 {00086 SelStartNorm = <a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> + <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a>;00087 SelLenNorm = abs(<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a>);00088 }00089 <span class="keywordflow">else</span>00090 {00091 SelStartNorm = <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a>;00092 SelLenNorm = <a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a>;00093 }00094 <span class="keywordflow">return</span> <a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a>.substr(SelStartNorm, SelLenNorm);00095 }00096 <span class="keywordflow">else</span>00097 {00098 <span class="keywordflow">return</span> <span class="stringliteral">""</span>;00099 }00100 }00101 00102 <a name="l00103"></a><a class="code" href="classwGui_1_1CEditBox.html#a7">00103</a> <span class="keywordtype">void</span> CEditBox::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00104 <span class="keyword"></span>{00105 CWindow::Draw();00106 00107 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00108 <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00109 <a class="code" href="classwGui_1_1CRect.html">CRect</a> DrawRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00110 DrawRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-3);00111 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-3);00112 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);00113 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> FontCenterPoint = <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a17">Center</a>();00114 00115 <span class="keywordflow">if</span> (m_bUseMask)00116 {00117 <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>->SetMaskChar(<span class="charliteral">'*'</span>);00118 }00119 <span class="keywordflow">else</span>00120 {00121 <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>->SetMaskChar(<span class="charliteral">' '</span>);00122 }00123 00124 <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a> FontColor = <a class="code" href="classwGui_1_1CEditBox.html#n7">m_bReadOnly</a> ? DEFAULT_DISABLED_LINE_COLOR : DEFAULT_LINE_COLOR;00125 <span class="keywordflow">if</span> (CApplication::Instance()->GetKeyFocus() == dynamic_cast<const CWindow*>(this) && !<a class="code" href="classwGui_1_1CEditBox.html#n7">m_bReadOnly</a>)00126 {00127 00128 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Offset;00129 std::vector<CRect> CharRects;00130 <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>->GetMetrics(0, &Offset, &CharRects);00131 00132 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> SelStartNorm = 0;00133 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> SelLenNorm = abs(<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a>);00134 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> < 0)00135 {00136 SelStartNorm = <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a> + <a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a>;00137 }00138 <span class="keywordflow">else</span>00139 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -