Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / embedding / tests / wxEmbed / GeckoFrame.cpp
blobd6ad74b3d069726b6c6dccf21319d88273a7c2d2
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: Mozilla-sample-code 1.0
4 * Copyright (c) 2002 Netscape Communications Corporation and
5 * other contributors
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this Mozilla sample software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do so, subject to the
13 * following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Contributor(s):
27 * Adam Lock <adamlock@netscape.com>
29 * ***** END LICENSE BLOCK ***** */
31 #include "global.h"
33 #include "GeckoFrame.h"
34 #include "GeckoContainer.h"
36 #include "nsIWebBrowserFocus.h"
37 #include "nsIClipboardCommands.h"
39 GeckoFrame::GeckoFrame() :
40 mGeckoWnd(NULL)
44 BEGIN_EVENT_TABLE(GeckoFrame, wxFrame)
45 EVT_ACTIVATE(GeckoFrame::OnActivate)
46 // Clipboard functions
47 EVT_MENU(XRCID("edit_cut"), GeckoFrame::OnEditCut)
48 EVT_UPDATE_UI(XRCID("edit_cut"), GeckoFrame::OnUpdateEditCut)
49 EVT_MENU(XRCID("edit_copy"), GeckoFrame::OnEditCopy)
50 EVT_UPDATE_UI(XRCID("edit_copy"), GeckoFrame::OnUpdateEditCopy)
51 EVT_MENU(XRCID("edit_paste"), GeckoFrame::OnEditPaste)
52 EVT_UPDATE_UI(XRCID("edit_paste"), GeckoFrame::OnUpdateEditPaste)
53 EVT_MENU(XRCID("edit_selectall"), GeckoFrame::OnEditSelectAll)
54 END_EVENT_TABLE()
57 bool GeckoFrame::SetupDefaultGeckoWindow()
59 mGeckoWnd = (GeckoWindow *) FindWindowById(XRCID("gecko"), this);
60 if (!mGeckoWnd)
61 return FALSE;
62 return SetupGeckoWindow(mGeckoWnd, this, getter_AddRefs(mWebBrowser));
65 bool GeckoFrame::SetupGeckoWindow(GeckoWindow *aGeckoWindow, GeckoContainerUI *aUI, nsIWebBrowser **aWebBrowser) const
67 if (!aGeckoWindow || !aUI)
68 return FALSE;
70 GeckoContainer *geckoContainer = new GeckoContainer(aUI);
71 if (!geckoContainer)
72 return FALSE;
74 mGeckoWnd->SetGeckoContainer(geckoContainer);
76 PRUint32 aChromeFlags = nsIWebBrowserChrome::CHROME_ALL;
77 geckoContainer->SetChromeFlags(aChromeFlags);
78 geckoContainer->SetParent(nsnull);
79 wxSize size = mGeckoWnd->GetClientSize();
81 // Insert the browser
82 geckoContainer->CreateBrowser(0, 0, size.GetWidth(), size.GetHeight(),
83 (nativeWindow) aGeckoWindow->GetHWND(), aWebBrowser);
85 nsCOMPtr<nsIBaseWindow> webBrowserAsWin = do_QueryInterface(*aWebBrowser);
86 if (webBrowserAsWin)
88 webBrowserAsWin->SetVisibility(PR_TRUE);
91 return TRUE;
94 void GeckoFrame::OnActivate(wxActivateEvent &event)
96 nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(mWebBrowser));
97 if (focus)
99 if (event.GetActive())
100 focus->Activate();
101 else
102 focus->Deactivate();
104 wxFrame::OnActivate(event);
107 void GeckoFrame::OnEditCut(wxCommandEvent &event)
109 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
110 if(clipCmds)
111 clipCmds->CutSelection();
114 void GeckoFrame::OnUpdateEditCut(wxUpdateUIEvent &event)
116 PRBool canCut = PR_FALSE;
117 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
118 if(clipCmds)
119 clipCmds->CanCutSelection(&canCut);
120 event.Enable(canCut ? true : false);
123 void GeckoFrame::OnEditCopy(wxCommandEvent &event)
125 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
126 if(clipCmds)
127 clipCmds->CopySelection();
130 void GeckoFrame::OnUpdateEditCopy(wxUpdateUIEvent &event)
132 PRBool canCopy = PR_FALSE;
133 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
134 if(clipCmds)
135 clipCmds->CanCopySelection(&canCopy);
136 event.Enable(canCopy ? true : false);
139 void GeckoFrame::OnEditPaste(wxCommandEvent &event)
141 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
142 if(clipCmds)
143 clipCmds->Paste();
146 void GeckoFrame::OnUpdateEditPaste(wxUpdateUIEvent &event)
148 PRBool canPaste = PR_FALSE;
149 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
150 if(clipCmds)
151 clipCmds->CanPaste(&canPaste);
152 event.Enable(canPaste ? true : false);
155 void GeckoFrame::OnEditSelectAll(wxCommandEvent &event)
157 nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
158 if(clipCmds)
159 clipCmds->SelectAll();
162 ///////////////////////////////////////////////////////////////////////////////
163 // GeckoContainerUI overrides
165 void GeckoFrame::SetFocus()
167 mGeckoWnd->SetFocus();