Back to index

lightning-sunbird  0.9+nobinonly
ChatFrame.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: Mozilla-sample-code 1.0
00003  *
00004  * Copyright (c) 2002 Netscape Communications Corporation and
00005  * other contributors
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this Mozilla sample software and associated documentation files
00009  * (the "Software"), to deal in the Software without restriction, including
00010  * without limitation the rights to use, copy, modify, merge, publish,
00011  * distribute, sublicense, and/or sell copies of the Software, and to permit
00012  * persons to whom the Software is furnished to do so, subject to the
00013  * following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included
00016  * in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00021  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00023  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00024  * DEALINGS IN THE SOFTWARE.
00025  *
00026  * Contributor(s):
00027  *   Adam Lock <adamlock@netscape.com>
00028  *
00029  * ***** END LICENSE BLOCK ***** */
00030 
00031 #include "global.h"
00032 
00033 #include "wx/strconv.h"
00034 
00035 #include "nsIWebNavigation.h"
00036 #include "nsIDOMDocument.h"
00037 #include "nsIDOMHTMLDocument.h"
00038 
00039 #include "ChatFrame.h"
00040 
00041 BEGIN_EVENT_TABLE(ChatFrame, GeckoFrame)
00042     EVT_TEXT_ENTER(XRCID("chat"),        ChatFrame::OnChat)
00043 END_EVENT_TABLE()
00044 
00045 ChatFrame::ChatFrame(wxWindow* aParent)
00046 {
00047     wxXmlResource::Get()->LoadFrame(this, aParent, wxT("chat_frame"));
00048 
00049     SetName("chat");
00050 
00051     SetIcon(wxICON(appicon));
00052 
00053     SetupDefaultGeckoWindow();
00054 
00055     nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
00056     webNav->LoadURI(NS_ConvertASCIItoUCS2("about:blank").get(),
00057         nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
00058 
00059 }
00060 
00061 void ChatFrame::OnChat(wxCommandEvent &event)
00062 {
00063     nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
00064     nsCOMPtr<nsIDOMDocument> doc;
00065     webNav->GetDocument(getter_AddRefs(doc));
00066     nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
00067     // doc->CreateElement(getter_AddRefs(element));
00068 
00069     wxTextCtrl *chatCtrl = (wxTextCtrl *) FindWindowById(XRCID("chat"), this);
00070     if (chatCtrl)
00071     {
00072         wxString html("<p>Foo: ");
00073         html += chatCtrl->GetValue();
00074         wxMBConv conv;
00075         nsAutoString htmlU(conv.cWX2WC(html));
00076         htmlDoc->Writeln(htmlU);
00077         chatCtrl->SetValue("");
00078     }
00079 }