334 lines
39 KiB
HTML
334 lines
39 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<title>wxLua: /mnt/share/devel/lua/wxLua/modules/wxlua/src/wxlcallb.cpp Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="main.html"><span>Main Page</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="dirs.html"><span>Directories</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
<li><a href="globals.html"><span>File Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="navpath"><a class="el" href="dir_15d5a205ad383328522db6a6be296af1.html">modules</a> » <a class="el" href="dir_b59b58daa92d206701e75411b2cef894.html">wxlua</a> » <a class="el" href="dir_83fe9eb5cda99cf12108735ec0aac68a.html">src</a>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>wxlcallb.cpp</h1><a href="wxlcallb_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
|
|
<a name="l00002"></a>00002 <span class="comment"></span><span class="comment">// Name: wxlcallb.cpp</span>
|
|
<a name="l00003"></a>00003 <span class="comment">// Purpose: wxLuaEventCallback and wxLuaWinDestroyCallback</span>
|
|
<a name="l00004"></a>00004 <span class="comment">// Author: Francis Irving, John Labenski</span>
|
|
<a name="l00005"></a>00005 <span class="comment">// Created: 11/05/2002</span>
|
|
<a name="l00006"></a>00006 <span class="comment">// Copyright: (c) 2002 Creature Labs. All rights reserved.</span>
|
|
<a name="l00007"></a>00007 <span class="comment">// Licence: wxWidgets licence</span><span class="comment"></span>
|
|
<a name="l00008"></a>00008 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
|
|
<a name="l00009"></a>00009 <span class="comment"></span>
|
|
<a name="l00010"></a>00010 <span class="comment">// For compilers that support precompilation, includes "wx/wx.h".</span>
|
|
<a name="l00011"></a>00011 <span class="preprocessor">#include "wx/wxprec.h"</span>
|
|
<a name="l00012"></a>00012
|
|
<a name="l00013"></a>00013 <span class="preprocessor">#ifdef __BORLANDC__</span>
|
|
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor"> #pragma hdrstop</span>
|
|
<a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00016"></a>00016 <span class="preprocessor"></span>
|
|
<a name="l00017"></a>00017 <span class="preprocessor">#ifndef WX_PRECOMP</span>
|
|
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor"> #include "wx/wx.h"</span>
|
|
<a name="l00019"></a>00019 <span class="preprocessor">#endif // WX_PRECOMP</span>
|
|
<a name="l00020"></a>00020 <span class="preprocessor"></span>
|
|
<a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="wxlcallb_8h.html">wxlua/include/wxlcallb.h</a>"</span>
|
|
<a name="l00022"></a>00022
|
|
<a name="l00023"></a>00023 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
<a name="l00024"></a>00024 <span class="comment">// wxLuaEventCallback</span>
|
|
<a name="l00025"></a>00025 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
<a name="l00026"></a>00026 <a class="code" href="wxlsock_8cpp.html#abdcf9eaaef19410a688aa559de382a29">IMPLEMENT_ABSTRACT_CLASS</a>(<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>, wxObject)
|
|
<a name="l00027"></a>00027
|
|
<a name="l00028"></a><a class="code" href="classwxLuaEventCallback.html#a022b6625b5844b42025be651adac40c8">00028</a> <a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>::<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>()
|
|
<a name="l00029"></a>00029 : m_luafunc_ref(0), <span class="comment">//m_wxlState(wxNullLuaState),</span>
|
|
<a name="l00030"></a>00030 m_evtHandler(NULL), m_id(wxID_ANY), m_last_id(wxID_ANY),
|
|
<a name="l00031"></a>00031 m_wxlBindEvent(NULL)
|
|
<a name="l00032"></a>00032 {
|
|
<a name="l00033"></a>00033 }
|
|
<a name="l00034"></a>00034
|
|
<a name="l00035"></a><a class="code" href="classwxLuaEventCallback.html#a3c21c3963687a58ab0c74d5b94f3c707">00035</a> <a class="code" href="classwxLuaEventCallback.html#a3c21c3963687a58ab0c74d5b94f3c707">wxLuaEventCallback::~wxLuaEventCallback</a>()
|
|
<a name="l00036"></a>00036 {
|
|
<a name="l00037"></a>00037 <span class="comment">// Remove the reference to the Lua function that we call</span>
|
|
<a name="l00038"></a>00038 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>())
|
|
<a name="l00039"></a>00039 {
|
|
<a name="l00040"></a>00040 <a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a26d311d6ee816331696ec18b4b1ee1d4">wxluaR_Unref</a>(<a class="code" href="classwxLuaEventCallback.html#a345f97641a497fb6b3184de9ea77a65b">m_luafunc_ref</a>, &<a class="code" href="wxlstate_8h.html#ac4ac0a3575fafde31e659ced85f69c4d">wxlua_lreg_refs_key</a>);
|
|
<a name="l00041"></a>00041 <span class="comment">// delete the reference to this handler</span>
|
|
<a name="l00042"></a>00042 <a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.<a class="code" href="classwxLuaState.html#ad2dcccb0c2ceb53b801faf492b513044">RemoveTrackedEventCallback</a>(<span class="keyword">this</span>);
|
|
<a name="l00043"></a>00043 }
|
|
<a name="l00044"></a>00044 }
|
|
<a name="l00045"></a>00045
|
|
<a name="l00046"></a><a class="code" href="classwxLuaEventCallback.html#a1fcc96964c39456fa77f152b8302cb8a">00046</a> wxString <a class="code" href="classwxLuaEventCallback.html#a1fcc96964c39456fa77f152b8302cb8a">wxLuaEventCallback::Connect</a>(<span class="keyword">const</span> <a class="code" href="classwxLuaState.html">wxLuaState</a>& wxlState, <span class="keywordtype">int</span> lua_func_stack_idx,
|
|
<a name="l00047"></a>00047 wxWindowID win_id, wxWindowID last_id,
|
|
<a name="l00048"></a>00048 wxEventType eventType, wxEvtHandler *evtHandler)
|
|
<a name="l00049"></a>00049 {
|
|
<a name="l00050"></a>00050 <span class="comment">// Assert too since these errors are serious and not just bad Lua code.</span>
|
|
<a name="l00051"></a>00051 wxCHECK_MSG(evtHandler != NULL, wxT(<span class="stringliteral">"Invalid wxEvtHandler in wxLuaEventCallback::Connect()"</span>), wxT(<span class="stringliteral">"Invalid wxEvtHandler in wxLuaEventCallback::Connect()"</span>));
|
|
<a name="l00052"></a>00052 wxCHECK_MSG((<a class="code" href="classwxLuaEventCallback.html#a24b10cd51688dc114ba08d770ab533aa">m_evtHandler</a> == NULL) && (<a class="code" href="classwxLuaEventCallback.html#a345f97641a497fb6b3184de9ea77a65b">m_luafunc_ref</a> == 0), wxT(<span class="stringliteral">"Attempting to reconnect a wxLuaEventCallback"</span>), wxT(<span class="stringliteral">"Attempting to reconnect a wxLuaEventCallback"</span>));
|
|
<a name="l00053"></a>00053 wxCHECK_MSG(wxlState.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>(), wxT(<span class="stringliteral">"Invalid wxLuaState"</span>), wxT(<span class="stringliteral">"Invalid wxLuaState"</span>));
|
|
<a name="l00054"></a>00054
|
|
<a name="l00055"></a>00055 <a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a> = wxlState;
|
|
<a name="l00056"></a>00056 <a class="code" href="classwxLuaEventCallback.html#a24b10cd51688dc114ba08d770ab533aa">m_evtHandler</a> = evtHandler;
|
|
<a name="l00057"></a>00057 <a class="code" href="classwxLuaEventCallback.html#a8c9bfe5e31a55df1f1ad3add4bc20bb8">m_id</a> = win_id;
|
|
<a name="l00058"></a>00058 <a class="code" href="classwxLuaEventCallback.html#a3ac255b4c1bcfe3c7803b765efcfa2bb">m_last_id</a> = last_id;
|
|
<a name="l00059"></a>00059
|
|
<a name="l00060"></a>00060 <a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a> = wxlState.<a class="code" href="classwxLuaState.html#abe8b0a31282c3e7e02a277502224109c">GetBindEvent</a>(eventType);
|
|
<a name="l00061"></a>00061
|
|
<a name="l00062"></a>00062 <span class="comment">// Do not install this invalid or unknown event type since we won't know</span>
|
|
<a name="l00063"></a>00063 <span class="comment">// what wxEvent type class to use and someone probably made a mistake.</span>
|
|
<a name="l00064"></a>00064 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a> == NULL)
|
|
<a name="l00065"></a>00065 {
|
|
<a name="l00066"></a>00066 <span class="keywordflow">return</span> wxString::Format(wxT(<span class="stringliteral">"wxLua: Invalid or unknown wxEventType for wxEvtHandler::Connect() : %d, winIds %d, %d."</span>),
|
|
<a name="l00067"></a>00067 (<span class="keywordtype">int</span>)eventType, win_id, last_id);
|
|
<a name="l00068"></a>00068 }
|
|
<a name="l00069"></a>00069
|
|
<a name="l00070"></a>00070 m_wxlState.AddTrackedEventCallback(<span class="keyword">this</span>);
|
|
<a name="l00071"></a>00071
|
|
<a name="l00072"></a>00072 <span class="comment">// create a reference to the Lua event handler function</span>
|
|
<a name="l00073"></a>00073 <span class="keywordflow">if</span> (lua_func_stack_idx != <a class="code" href="wxlcallb_8h.html#a2c65ce5032e6ce9b5e202ac44376ac2e">WXLUAEVENTCALLBACK_NOROUTINE</a>)
|
|
<a name="l00074"></a>00074 <a class="code" href="classwxLuaEventCallback.html#a345f97641a497fb6b3184de9ea77a65b">m_luafunc_ref</a> = m_wxlState.wxluaR_Ref(lua_func_stack_idx, &<a class="code" href="wxlstate_8h.html#ac4ac0a3575fafde31e659ced85f69c4d">wxlua_lreg_refs_key</a>);
|
|
<a name="l00075"></a>00075
|
|
<a name="l00076"></a>00076 <span class="comment">// Note: We use the callback userdata and not the event sink since the event sink</span>
|
|
<a name="l00077"></a>00077 <span class="comment">// requires a wxEvtHandler object which is a fairly large class.</span>
|
|
<a name="l00078"></a>00078 <span class="comment">// The userdata (i.e. this) is also deleted for us which makes our life easier.</span>
|
|
<a name="l00079"></a>00079 <a class="code" href="classwxLuaEventCallback.html#a24b10cd51688dc114ba08d770ab533aa">m_evtHandler</a>->Connect(win_id, last_id, eventType,
|
|
<a name="l00080"></a>00080 (wxObjectEventFunction)&<a class="code" href="classwxLuaEventCallback.html#a542d75e579cba50f56129bd2b2baae3d">wxLuaEventCallback::OnAllEvents</a>,
|
|
<a name="l00081"></a>00081 <span class="keyword">this</span>);
|
|
<a name="l00082"></a>00082 <span class="keywordflow">return</span> wxEmptyString;
|
|
<a name="l00083"></a>00083 }
|
|
<a name="l00084"></a>00084
|
|
<a name="l00085"></a><a class="code" href="classwxLuaEventCallback.html#a6a9159713a598aca57598912af845070">00085</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaEventCallback.html#a6a9159713a598aca57598912af845070">wxLuaEventCallback::ClearwxLuaState</a>()
|
|
<a name="l00086"></a>00086 {
|
|
<a name="l00087"></a>00087 <a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.UnRef();
|
|
<a name="l00088"></a>00088 }
|
|
<a name="l00089"></a>00089
|
|
<a name="l00090"></a><a class="code" href="classwxLuaEventCallback.html#a7d2dbf42ab8d4ddc22df1bd75ab095b6">00090</a> wxString <a class="code" href="classwxLuaEventCallback.html#a7d2dbf42ab8d4ddc22df1bd75ab095b6">wxLuaEventCallback::GetInfo</a>()<span class="keyword"> const</span>
|
|
<a name="l00091"></a>00091 <span class="keyword"></span>{
|
|
<a name="l00092"></a>00092 <span class="keywordflow">return</span> wxString::Format(wxT(<span class="stringliteral">"%s(%d) -> wxLuaEventCallback(%p, ids %d, %d)|wxEvtHandler(%p) -> %s : %s"</span>),
|
|
<a name="l00093"></a>00093 <a class="code" href="wxlstate_8h.html#aaa3dbc7e667edd1e7409725fe338f4e8">lua2wx</a>(<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a> ? <a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a>-><a class="code" href="structwxLuaBindEvent.html#a6de864ceccf61c077d89fe8abe1288ee">name</a> : <span class="stringliteral">"?"</span>).c_str(), (int)<a class="code" href="classwxLuaEventCallback.html#a9d261c62f81fbdebbb270eeaf1ac3ac6">GetEventType</a>(),
|
|
<a name="l00094"></a>00094 <span class="keyword">this</span>, <a class="code" href="classwxLuaEventCallback.html#a8c9bfe5e31a55df1f1ad3add4bc20bb8">m_id</a>, <a class="code" href="classwxLuaEventCallback.html#a3ac255b4c1bcfe3c7803b765efcfa2bb">m_last_id</a>,
|
|
<a name="l00095"></a>00095 <a class="code" href="classwxLuaEventCallback.html#a24b10cd51688dc114ba08d770ab533aa">m_evtHandler</a>, m_evtHandler->GetClassInfo()->GetClassName(),
|
|
<a name="l00096"></a>00096 <a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a2479a06481b5a8e28f292f4e4b81b517">GetwxLuaTypeName</a>(*<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a>-><a class="code" href="structwxLuaBindEvent.html#a608a7a408284016c0e42c3c1715b82c2">wxluatype</a>).c_str());
|
|
<a name="l00097"></a>00097 }
|
|
<a name="l00098"></a>00098
|
|
<a name="l00099"></a><a class="code" href="classwxLuaEventCallback.html#a542d75e579cba50f56129bd2b2baae3d">00099</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaEventCallback.html#a542d75e579cba50f56129bd2b2baae3d">wxLuaEventCallback::OnAllEvents</a>(wxEvent& event)
|
|
<a name="l00100"></a>00100 {
|
|
<a name="l00101"></a>00101 wxEventType evtType = <span class="keyword">event</span>.GetEventType();
|
|
<a name="l00102"></a>00102
|
|
<a name="l00103"></a>00103 <span class="comment">// Get the wxLuaEventCallback instance to use which is NOT "this" since</span>
|
|
<a name="l00104"></a>00104 <span class="comment">// "this" is a central event handler function. i.e. this != theCallback</span>
|
|
<a name="l00105"></a>00105 <a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a> *theCallback = (<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a> *)event.m_callbackUserData;
|
|
<a name="l00106"></a>00106 wxCHECK_RET(theCallback != NULL, wxT(<span class="stringliteral">"Invalid wxLuaEventCallback in wxEvent user data"</span>));
|
|
<a name="l00107"></a>00107
|
|
<a name="l00108"></a>00108 <span class="comment">// Not an error if !Ok(), the wxLuaState is cleared during shutdown or after a destroy event.</span>
|
|
<a name="l00109"></a>00109 <a class="code" href="classwxLuaState.html">wxLuaState</a> wxlState(theCallback-><a class="code" href="classwxLuaEventCallback.html#a5fb1611ad72c116f78ab6f7ba9b95283">GetwxLuaState</a>());
|
|
<a name="l00110"></a>00110 <span class="keywordflow">if</span> (wxlState.Ok())
|
|
<a name="l00111"></a>00111 {
|
|
<a name="l00112"></a>00112 wxlState.SetInEventType(evtType);
|
|
<a name="l00113"></a>00113 theCallback-><a class="code" href="classwxLuaEventCallback.html#a294ddcf2cc0bdc0be0ed4f5c554e0ac4">OnEvent</a>(&event);
|
|
<a name="l00114"></a>00114 wxlState.SetInEventType(wxEVT_NULL);
|
|
<a name="l00115"></a>00115 }
|
|
<a name="l00116"></a>00116
|
|
<a name="l00117"></a>00117 <span class="comment">// we want the wxLuaWinDestroyCallback to get this too</span>
|
|
<a name="l00118"></a>00118 <span class="keywordflow">if</span> (evtType == wxEVT_DESTROY)
|
|
<a name="l00119"></a>00119 <span class="keyword">event</span>.Skip(<span class="keyword">true</span>);
|
|
<a name="l00120"></a>00120 }
|
|
<a name="l00121"></a>00121
|
|
<a name="l00122"></a><a class="code" href="classwxLuaEventCallback.html#a294ddcf2cc0bdc0be0ed4f5c554e0ac4">00122</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaEventCallback.html#a294ddcf2cc0bdc0be0ed4f5c554e0ac4">wxLuaEventCallback::OnEvent</a>(wxEvent *event)
|
|
<a name="l00123"></a>00123 {
|
|
<a name="l00124"></a>00124 <span class="comment">// Cannot call it if Lua is gone or the interpreter has been destroyed</span>
|
|
<a name="l00125"></a>00125 <span class="comment">// This can happen when the program exits since windows may be destroyed</span>
|
|
<a name="l00126"></a>00126 <span class="comment">// after Lua has been deleted.</span>
|
|
<a name="l00127"></a>00127 <span class="keywordflow">if</span> (!<a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>())
|
|
<a name="l00128"></a>00128 <span class="keywordflow">return</span>;
|
|
<a name="l00129"></a>00129
|
|
<a name="l00130"></a>00130 <span class="comment">// ref the state in case this generates a wxEVT_DESTROY which clears us</span>
|
|
<a name="l00131"></a>00131 <a class="code" href="classwxLuaState.html">wxLuaState</a> wxlState(<a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">m_wxlState</a>);
|
|
<a name="l00132"></a>00132
|
|
<a name="l00133"></a>00133 <span class="keywordtype">int</span> event_wxl_type = <a class="code" href="wxlbind_8h.html#aeb150b964405f526ef77087288f403b2">WXLUA_TUNKNOWN</a>;
|
|
<a name="l00134"></a>00134
|
|
<a name="l00135"></a>00135 <span class="comment">// If !m_wxlBindEvent, we would have errored in Connect(), but don't crash...</span>
|
|
<a name="l00136"></a>00136 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a> != NULL)
|
|
<a name="l00137"></a>00137 {
|
|
<a name="l00138"></a>00138 event_wxl_type = *<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a>-><a class="code" href="structwxLuaBindEvent.html#a608a7a408284016c0e42c3c1715b82c2">wxluatype</a>;
|
|
<a name="l00139"></a>00139
|
|
<a name="l00140"></a>00140 <span class="comment">// These wxEventTypes can be wxScrollEvents or wxSpinEvents</span>
|
|
<a name="l00141"></a>00141 <span class="comment">// wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN, wxEVT_SCROLL_THUMBTRACK</span>
|
|
<a name="l00142"></a>00142
|
|
<a name="l00143"></a>00143 <span class="keywordflow">if</span> ((strcmp(<a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">m_wxlBindEvent</a>-><a class="code" href="structwxLuaBindEvent.html#a6de864ceccf61c077d89fe8abe1288ee">name</a>, <span class="stringliteral">"wxScrollEvent"</span>) == 0) &&
|
|
<a name="l00144"></a>00144 (event->GetClassInfo()->GetClassName() == wxString(wxT(<span class="stringliteral">"wxSpinEvent"</span>))))
|
|
<a name="l00145"></a>00145 {
|
|
<a name="l00146"></a>00146 <span class="keyword">const</span> <a class="code" href="structwxLuaBindClass.html">wxLuaBindClass</a> *wxlClass = wxlState.<a class="code" href="classwxLuaState.html#a40bd580168967f978143eadfcbc43aa5">GetBindClass</a>(<span class="stringliteral">"wxSpinEvent"</span>);
|
|
<a name="l00147"></a>00147 <span class="keywordflow">if</span> (wxlClass != NULL)
|
|
<a name="l00148"></a>00148 event_wxl_type = *wxlClass-><a class="code" href="structwxLuaBindClass.html#a487a56c7a763a21041272c4b053e6c99">wxluatype</a>;
|
|
<a name="l00149"></a>00149 <span class="keywordflow">else</span>
|
|
<a name="l00150"></a>00150 event_wxl_type = *<a class="code" href="wxlbind_8cpp.html#aea95a7e5610e8d338700175ede7e8b28">p_wxluatype_wxEvent</a>; <span class="comment">// get the generic wxluatype_wxEvent</span>
|
|
<a name="l00151"></a>00151 }
|
|
<a name="l00152"></a>00152 }
|
|
<a name="l00153"></a>00153 <span class="keywordflow">else</span>
|
|
<a name="l00154"></a>00154 event_wxl_type = *<a class="code" href="wxlbind_8cpp.html#aea95a7e5610e8d338700175ede7e8b28">p_wxluatype_wxEvent</a>; <span class="comment">// get the generic wxluatype_wxEvent</span>
|
|
<a name="l00155"></a>00155
|
|
<a name="l00156"></a>00156 <span class="comment">// Should know our event type, but error out in case we don't</span>
|
|
<a name="l00157"></a>00157 wxCHECK_RET(event_wxl_type != <a class="code" href="wxlbind_8h.html#aeb150b964405f526ef77087288f403b2">WXLUA_TUNKNOWN</a>, wxT(<span class="stringliteral">"Unknown wxEvent wxLua tag for : "</span>) + wxString(event->GetClassInfo()->GetClassName()));
|
|
<a name="l00158"></a>00158
|
|
<a name="l00159"></a>00159 wxlState.<a class="code" href="classwxLuaState.html#a4371f5ded50509ba5b0e089aa2a3c750">lua_CheckStack</a>(LUA_MINSTACK);
|
|
<a name="l00160"></a>00160 <span class="keywordtype">int</span> oldTop = wxlState.<a class="code" href="classwxLuaState.html#ae9d1c33abd2af7e081fa71a42ca28a26">lua_GetTop</a>();
|
|
<a name="l00161"></a>00161 <span class="keywordflow">if</span> (wxlState.<a class="code" href="classwxLuaState.html#a119cc5105d9f11af426a6bb5db6fe863">wxluaR_GetRef</a>(<a class="code" href="classwxLuaEventCallback.html#a345f97641a497fb6b3184de9ea77a65b">m_luafunc_ref</a>, &<a class="code" href="wxlstate_8h.html#ac4ac0a3575fafde31e659ced85f69c4d">wxlua_lreg_refs_key</a>))
|
|
<a name="l00162"></a>00162 {
|
|
<a name="l00163"></a>00163 wxlState.<a class="code" href="classwxLuaState.html#aeff1ffb143ad768c0c37ff877aacfa62">lua_PushValue</a>(LUA_GLOBALSINDEX);
|
|
<a name="l00164"></a>00164 <span class="keywordflow">if</span> (wxlState.<a class="code" href="classwxLuaState.html#a452fc13b21c961150fc1ddb9c1102241">lua_SetFenv</a>(-2) != 0)
|
|
<a name="l00165"></a>00165 {
|
|
<a name="l00166"></a>00166 <span class="comment">// Don't track the wxEvent since we don't own it and tracking it</span>
|
|
<a name="l00167"></a>00167 <span class="comment">// causes clashes in the object registry table since many can be</span>
|
|
<a name="l00168"></a>00168 <span class="comment">// created and deleted and the mem address is resused by C++.</span>
|
|
<a name="l00169"></a>00169 wxlState.<a class="code" href="classwxLuaState.html#a1ddca063dc0adeabba008a3249ac92cc">wxluaT_PushUserDataType</a>(event, event_wxl_type, <span class="keyword">false</span>);
|
|
<a name="l00170"></a>00170 wxlState.<a class="code" href="classwxLuaState.html#a9359504a70a5819c3c27a14c590d8d46">LuaPCall</a>(1, 0); <span class="comment">// one input no returns</span>
|
|
<a name="l00171"></a>00171 }
|
|
<a name="l00172"></a>00172 <span class="keywordflow">else</span>
|
|
<a name="l00173"></a>00173 wxlState.<a class="code" href="classwxLuaState.html#a4925fb35a1622f81fc9c5dc5820e27d8">wxlua_Error</a>(<span class="stringliteral">"wxLua: wxEvtHandler::Connect() in wxLuaEventCallback::OnEvent(), function is not a Lua function."</span>);
|
|
<a name="l00174"></a>00174 }
|
|
<a name="l00175"></a>00175 <span class="keywordflow">else</span>
|
|
<a name="l00176"></a>00176 wxlState.<a class="code" href="classwxLuaState.html#a4925fb35a1622f81fc9c5dc5820e27d8">wxlua_Error</a>(<span class="stringliteral">"wxLua: wxEvtHandler::Connect() in wxLuaEventCallback::OnEvent(), function to call is not refed."</span>);
|
|
<a name="l00177"></a>00177
|
|
<a name="l00178"></a>00178 wxlState.<a class="code" href="classwxLuaState.html#ad39adb85b7e7010691f51bd3f6fe3161">lua_SetTop</a>(oldTop); <span class="comment">// pop function and error message from the stack (if they're there)</span>
|
|
<a name="l00179"></a>00179 }
|
|
<a name="l00180"></a>00180
|
|
<a name="l00181"></a>00181 <span class="comment">// ----------------------------------------------------------------------------</span>
|
|
<a name="l00182"></a>00182 <span class="comment">// wxLuaWinDestroyCallback</span>
|
|
<a name="l00183"></a>00183 <span class="comment">// ----------------------------------------------------------------------------</span>
|
|
<a name="l00184"></a>00184 <a class="code" href="wxlsock_8cpp.html#abdcf9eaaef19410a688aa559de382a29">IMPLEMENT_ABSTRACT_CLASS</a>(<a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>, wxObject)
|
|
<a name="l00185"></a>00185
|
|
<a name="l00186"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a34ed9c1a9607cc33705fafb9dc2e441f">00186</a> <a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>::<a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>(const <a class="code" href="classwxLuaState.html">wxLuaState</a>& wxlState,
|
|
<a name="l00187"></a>00187 wxWindow* win)
|
|
<a name="l00188"></a>00188 :m_wxlState(wxlState), m_window(win)
|
|
<a name="l00189"></a>00189 {
|
|
<a name="l00190"></a>00190 wxCHECK_RET(m_wxlState.Ok(), wxT(<span class="stringliteral">"Invalid wxLuaState"</span>));
|
|
<a name="l00191"></a>00191 wxCHECK_RET(m_window != NULL, wxT(<span class="stringliteral">"Invalid wxWindow"</span>));
|
|
<a name="l00192"></a>00192
|
|
<a name="l00193"></a>00193 m_wxlState.AddTrackedWinDestroyCallback(<span class="keyword">this</span>);
|
|
<a name="l00194"></a>00194
|
|
<a name="l00195"></a>00195 <span class="comment">// connect the event handler and set this as the callback user data</span>
|
|
<a name="l00196"></a>00196 m_window->Connect(m_window->GetId(), wxEVT_DESTROY,
|
|
<a name="l00197"></a>00197 (wxObjectEventFunction)&<a class="code" href="classwxLuaWinDestroyCallback.html#a3368c5f7d8ee9bd2f7b011a27fe18eb6">wxLuaWinDestroyCallback::OnAllDestroyEvents</a>,
|
|
<a name="l00198"></a>00198 <span class="keyword">this</span>);
|
|
<a name="l00199"></a>00199 }
|
|
<a name="l00200"></a>00200
|
|
<a name="l00201"></a><a class="code" href="classwxLuaWinDestroyCallback.html#ad70cb7ac5de000578fa244586f0cf716">00201</a> <a class="code" href="classwxLuaWinDestroyCallback.html#ad70cb7ac5de000578fa244586f0cf716">wxLuaWinDestroyCallback::~wxLuaWinDestroyCallback</a>()
|
|
<a name="l00202"></a>00202 {
|
|
<a name="l00203"></a>00203 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>())
|
|
<a name="l00204"></a>00204 {
|
|
<a name="l00205"></a>00205 <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a871e9608f89114885a076d2c11605fa4">RemoveTrackedWinDestroyCallback</a>(<span class="keyword">this</span>);
|
|
<a name="l00206"></a>00206 <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#aa94f7693d356d05c4b5fc2019fe02031">RemoveTrackedWindow</a>(<a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>);
|
|
<a name="l00207"></a>00207 }
|
|
<a name="l00208"></a>00208 }
|
|
<a name="l00209"></a>00209
|
|
<a name="l00210"></a><a class="code" href="classwxLuaWinDestroyCallback.html#adfc7590cb179efa4d3eb4c38fb903aba">00210</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaWinDestroyCallback.html#adfc7590cb179efa4d3eb4c38fb903aba">wxLuaWinDestroyCallback::ClearwxLuaState</a>()
|
|
<a name="l00211"></a>00211 {
|
|
<a name="l00212"></a>00212 <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.UnRef();
|
|
<a name="l00213"></a>00213 }
|
|
<a name="l00214"></a>00214
|
|
<a name="l00215"></a><a class="code" href="classwxLuaWinDestroyCallback.html#aa1ebb2002abc2ffc7d09c3c33a94e852">00215</a> wxString <a class="code" href="classwxLuaWinDestroyCallback.html#aa1ebb2002abc2ffc7d09c3c33a94e852">wxLuaWinDestroyCallback::GetInfo</a>()<span class="keyword"> const</span>
|
|
<a name="l00216"></a>00216 <span class="keyword"></span>{
|
|
<a name="l00217"></a>00217 wxString winName(wxT(<span class="stringliteral">"wxWindow?"</span>));
|
|
<a name="l00218"></a>00218 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a> && <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>->GetClassInfo())
|
|
<a name="l00219"></a>00219 winName = <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>->GetClassInfo()->GetClassName();
|
|
<a name="l00220"></a>00220
|
|
<a name="l00221"></a>00221 <span class="keywordflow">return</span> wxString::Format(wxT(<span class="stringliteral">"%s(%p, id=%d)|wxLuaDestroyCallback(%p)"</span>),
|
|
<a name="l00222"></a>00222 winName.c_str(), <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>, <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a> ? <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>->GetId() : -1,
|
|
<a name="l00223"></a>00223 <span class="keyword">this</span>);
|
|
<a name="l00224"></a>00224 }
|
|
<a name="l00225"></a>00225
|
|
<a name="l00226"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a3368c5f7d8ee9bd2f7b011a27fe18eb6">00226</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaWinDestroyCallback.html#a3368c5f7d8ee9bd2f7b011a27fe18eb6">wxLuaWinDestroyCallback::OnAllDestroyEvents</a>(wxWindowDestroyEvent& event)
|
|
<a name="l00227"></a>00227 {
|
|
<a name="l00228"></a>00228 <span class="comment">// Central handler for events, forward to the specific instance</span>
|
|
<a name="l00229"></a>00229 <a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a> *theCallback = (<a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a> *)event.m_callbackUserData;
|
|
<a name="l00230"></a>00230 if (theCallback && (((wxWindow*)event.GetEventObject()) == theCallback-><a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>))
|
|
<a name="l00231"></a>00231 {
|
|
<a name="l00232"></a>00232 theCallback-><a class="code" href="classwxLuaWinDestroyCallback.html#a0a3d1b7fbd67e2872a3c2d2b7c381624">OnDestroy</a>(event);
|
|
<a name="l00233"></a>00233 }
|
|
<a name="l00234"></a>00234 <span class="keywordflow">else</span>
|
|
<a name="l00235"></a>00235 <span class="keyword">event</span>.Skip();
|
|
<a name="l00236"></a>00236 }
|
|
<a name="l00237"></a>00237
|
|
<a name="l00238"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a0a3d1b7fbd67e2872a3c2d2b7c381624">00238</a> <span class="keywordtype">void</span> <a class="code" href="classwxLuaWinDestroyCallback.html#a0a3d1b7fbd67e2872a3c2d2b7c381624">wxLuaWinDestroyCallback::OnDestroy</a>(wxWindowDestroyEvent& event)
|
|
<a name="l00239"></a>00239 {
|
|
<a name="l00240"></a>00240 <span class="keyword">event</span>.Skip();
|
|
<a name="l00241"></a>00241
|
|
<a name="l00242"></a>00242 <span class="comment">// FIXME - Is it an error to receive an event after you've deleted Lua?</span>
|
|
<a name="l00243"></a>00243 <span class="comment">// probably not if Lua is getting shutdown</span>
|
|
<a name="l00244"></a>00244
|
|
<a name="l00245"></a>00245 <span class="comment">// Note: do not remove from wxLuaState's destroyHandlerList here, wait 'till destructor</span>
|
|
<a name="l00246"></a>00246 <span class="keywordflow">if</span> (<a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>())
|
|
<a name="l00247"></a>00247 {
|
|
<a name="l00248"></a>00248 lua_State* L = <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#af0b735eca529b1fc428a0aa08d0b7434">GetLuaState</a>();
|
|
<a name="l00249"></a>00249
|
|
<a name="l00250"></a>00250 <span class="comment">// clear the metatable for all userdata we're tracking.</span>
|
|
<a name="l00251"></a>00251 <a class="code" href="wxlstate_8h.html#a76fa03ffe7ba99804c524d86e17260db">wxluaO_untrackweakobject</a>(L, NULL, <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>);
|
|
<a name="l00252"></a>00252 <a class="code" href="wxlstate_8h.html#abfb64621a5e2ba46114e81a28731c79f">wxlua_removederivedmethods</a>(L, <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>);
|
|
<a name="l00253"></a>00253
|
|
<a name="l00254"></a>00254 <span class="comment">// Clear our own pointer to this window</span>
|
|
<a name="l00255"></a>00255 <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#aa94f7693d356d05c4b5fc2019fe02031">RemoveTrackedWindow</a>(<a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>);
|
|
<a name="l00256"></a>00256
|
|
<a name="l00257"></a>00257 wxEvtHandler* evtHandler = <a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>->GetEventHandler();
|
|
<a name="l00258"></a>00258
|
|
<a name="l00259"></a>00259 <span class="comment">// Finally, clear out the wxLuaEventCallbacks for the very odd cases where</span>
|
|
<a name="l00260"></a>00260 <span class="comment">// (activation) events can be sent during destruction. These can happen</span>
|
|
<a name="l00261"></a>00261 <span class="comment">// if you pop up a modal dialog (asking if they want to save perhaps)</span>
|
|
<a name="l00262"></a>00262 <span class="comment">// and when the dialog is closed the frame below sends an activation event,</span>
|
|
<a name="l00263"></a>00263 <span class="comment">// but we're right in the middle of being destroyed and we crash.</span>
|
|
<a name="l00264"></a>00264
|
|
<a name="l00265"></a>00265 lua_pushlightuserdata(L, &<a class="code" href="wxlstate_8h.html#a034985fb7df51670c3b6a024329496fa">wxlua_lreg_evtcallbacks_key</a>); <span class="comment">// push key</span>
|
|
<a name="l00266"></a>00266 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// pop key, push value (table)</span>
|
|
<a name="l00267"></a>00267
|
|
<a name="l00268"></a>00268 lua_pushnil(L);
|
|
<a name="l00269"></a>00269 <span class="keywordflow">while</span> (lua_next(L, -2) != 0)
|
|
<a name="l00270"></a>00270 {
|
|
<a name="l00271"></a>00271 <span class="comment">// value = -1, key = -2, table = -3</span>
|
|
<a name="l00272"></a>00272 <a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>* wxlCallback = (<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>*)lua_touserdata(L, -2);
|
|
<a name="l00273"></a>00273 wxCHECK_RET(wxlCallback, wxT(<span class="stringliteral">"Invalid wxLuaEventCallback"</span>));
|
|
<a name="l00274"></a>00274
|
|
<a name="l00275"></a>00275 <span class="keywordflow">if</span> ((wxlCallback-><a class="code" href="classwxLuaEventCallback.html#a43a1795558a72d6ba6f4f5a563d7a8e6">GetEvtHandler</a>() == evtHandler) ||
|
|
<a name="l00276"></a>00276 (wxlCallback-><a class="code" href="classwxLuaEventCallback.html#a43a1795558a72d6ba6f4f5a563d7a8e6">GetEvtHandler</a>() == (wxEvtHandler*)<a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">m_window</a>))
|
|
<a name="l00277"></a>00277 {
|
|
<a name="l00278"></a>00278 <span class="comment">// remove the ref to the routine since we're clearing the wxLuaState</span>
|
|
<a name="l00279"></a>00279 <span class="comment">// See ~wxLuaEventCallback</span>
|
|
<a name="l00280"></a>00280 <a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">m_wxlState</a>.<a class="code" href="classwxLuaState.html#a26d311d6ee816331696ec18b4b1ee1d4">wxluaR_Unref</a>(wxlCallback-><a class="code" href="classwxLuaEventCallback.html#a650ca5aaf3907f84b3e9ae5ee5bf4a76">GetLuaFuncRef</a>(), &<a class="code" href="wxlstate_8h.html#ac4ac0a3575fafde31e659ced85f69c4d">wxlua_lreg_refs_key</a>);
|
|
<a name="l00281"></a>00281 wxlCallback-><a class="code" href="classwxLuaEventCallback.html#a6a9159713a598aca57598912af845070">ClearwxLuaState</a>();
|
|
<a name="l00282"></a>00282
|
|
<a name="l00283"></a>00283 lua_pop(L, 1); <span class="comment">// pop value</span>
|
|
<a name="l00284"></a>00284
|
|
<a name="l00285"></a>00285 <span class="comment">// The code below is the equivalent of this, but works while iterating</span>
|
|
<a name="l00286"></a>00286 <span class="comment">// "m_wxlState.RemoveTrackedEventCallback(wxlCallback);"</span>
|
|
<a name="l00287"></a>00287
|
|
<a name="l00288"></a>00288 lua_pushvalue(L, -1); <span class="comment">// copy key for next iteration</span>
|
|
<a name="l00289"></a>00289 lua_pushnil(L);
|
|
<a name="l00290"></a>00290 lua_rawset(L, -4); <span class="comment">// set t[key] = nil to remove it</span>
|
|
<a name="l00291"></a>00291 }
|
|
<a name="l00292"></a>00292 <span class="keywordflow">else</span>
|
|
<a name="l00293"></a>00293 lua_pop(L, 1); <span class="comment">// pop value, lua_next will pop key at end</span>
|
|
<a name="l00294"></a>00294 }
|
|
<a name="l00295"></a>00295
|
|
<a name="l00296"></a>00296 lua_pop(L, 1); <span class="comment">// pop table</span>
|
|
<a name="l00297"></a>00297 }
|
|
<a name="l00298"></a>00298 }
|
|
</pre></div></div>
|
|
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue Jul 13 10:30:39 2010 for wxLua by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
|
</body>
|
|
</html>
|