Back to index

lightning-sunbird  0.9+nobinonly
GeckoFrame.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 "GeckoFrame.h"
00034 #include "GeckoContainer.h"
00035 
00036 #include "nsIWebBrowserFocus.h"
00037 #include "nsIClipboardCommands.h"
00038 
00039 GeckoFrame::GeckoFrame() :
00040     mGeckoWnd(NULL)
00041 {
00042 }
00043 
00044 BEGIN_EVENT_TABLE(GeckoFrame, wxFrame)
00045     EVT_ACTIVATE(GeckoFrame::OnActivate) 
00046     // Clipboard functions
00047     EVT_MENU(XRCID("edit_cut"),         GeckoFrame::OnEditCut)
00048     EVT_UPDATE_UI(XRCID("edit_cut"),    GeckoFrame::OnUpdateEditCut)
00049     EVT_MENU(XRCID("edit_copy"),        GeckoFrame::OnEditCopy)
00050     EVT_UPDATE_UI(XRCID("edit_copy"),   GeckoFrame::OnUpdateEditCopy)
00051     EVT_MENU(XRCID("edit_paste"),       GeckoFrame::OnEditPaste) 
00052     EVT_UPDATE_UI(XRCID("edit_paste"),  GeckoFrame::OnUpdateEditPaste)
00053     EVT_MENU(XRCID("edit_selectall"),   GeckoFrame::OnEditSelectAll)
00054 END_EVENT_TABLE()
00055 
00056 
00057 bool GeckoFrame::SetupDefaultGeckoWindow()
00058 {
00059     mGeckoWnd  = (GeckoWindow *) FindWindowById(XRCID("gecko"), this);
00060     if (!mGeckoWnd)
00061         return FALSE;
00062     return SetupGeckoWindow(mGeckoWnd, this, getter_AddRefs(mWebBrowser));
00063 }
00064 
00065 bool GeckoFrame::SetupGeckoWindow(GeckoWindow *aGeckoWindow, GeckoContainerUI *aUI, nsIWebBrowser **aWebBrowser) const
00066 {
00067     if (!aGeckoWindow || !aUI)
00068         return FALSE;
00069 
00070     GeckoContainer *geckoContainer = new GeckoContainer(aUI);
00071     if (!geckoContainer)
00072         return FALSE;
00073 
00074     mGeckoWnd->SetGeckoContainer(geckoContainer);
00075 
00076     PRUint32 aChromeFlags = nsIWebBrowserChrome::CHROME_ALL;
00077     geckoContainer->SetChromeFlags(aChromeFlags);
00078     geckoContainer->SetParent(nsnull);
00079     wxSize size = mGeckoWnd->GetClientSize();
00080 
00081     // Insert the browser
00082     geckoContainer->CreateBrowser(0, 0, size.GetWidth(), size.GetHeight(),
00083         (nativeWindow) aGeckoWindow->GetHWND(), aWebBrowser);
00084 
00085     nsCOMPtr<nsIBaseWindow> webBrowserAsWin = do_QueryInterface(*aWebBrowser);
00086     if (webBrowserAsWin)
00087     {
00088         webBrowserAsWin->SetVisibility(PR_TRUE);
00089     }
00090 
00091     return TRUE;
00092 }
00093 
00094 void GeckoFrame::OnActivate(wxActivateEvent &event)
00095 {
00096     nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(mWebBrowser));
00097     if (focus)
00098     {
00099         if (event.GetActive())
00100             focus->Activate();
00101         else
00102             focus->Deactivate();
00103     }
00104     wxFrame::OnActivate(event);
00105 }
00106 
00107 void GeckoFrame::OnEditCut(wxCommandEvent &event)
00108 {
00109     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00110     if(clipCmds)
00111         clipCmds->CutSelection();
00112 }
00113 
00114 void GeckoFrame::OnUpdateEditCut(wxUpdateUIEvent &event)
00115 {
00116     PRBool canCut = PR_FALSE;
00117     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00118     if(clipCmds)
00119         clipCmds->CanCutSelection(&canCut);
00120     event.Enable(canCut ? true : false);
00121 }
00122 
00123 void GeckoFrame::OnEditCopy(wxCommandEvent &event)
00124 {
00125     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00126     if(clipCmds)
00127         clipCmds->CopySelection();
00128 }
00129 
00130 void GeckoFrame::OnUpdateEditCopy(wxUpdateUIEvent &event)
00131 {
00132     PRBool canCopy = PR_FALSE;
00133     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00134     if(clipCmds)
00135         clipCmds->CanCopySelection(&canCopy);
00136     event.Enable(canCopy ? true : false);
00137 }
00138 
00139 void GeckoFrame::OnEditPaste(wxCommandEvent &event)
00140 {
00141     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00142     if(clipCmds)
00143         clipCmds->Paste();
00144 }
00145 
00146 void GeckoFrame::OnUpdateEditPaste(wxUpdateUIEvent &event)
00147 {
00148     PRBool canPaste = PR_FALSE;
00149     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00150     if(clipCmds)
00151         clipCmds->CanPaste(&canPaste);
00152     event.Enable(canPaste ? true : false);
00153 }
00154 
00155 void GeckoFrame::OnEditSelectAll(wxCommandEvent &event)
00156 {
00157     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00158     if(clipCmds)
00159         clipCmds->SelectAll();
00160 }
00161 
00163 // GeckoContainerUI overrides
00164 
00165 void GeckoFrame::SetFocus()
00166 {
00167     mGeckoWnd->SetFocus();
00168 }
00169