1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: Mozilla-sample-code 1.0
4 * Copyright (c) 2002 Netscape Communications Corporation and
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.
27 * Adam Lock <adamlock@netscape.com>
29 * ***** END LICENSE BLOCK ***** */
33 #include "GeckoFrame.h"
34 #include "GeckoContainer.h"
36 #include "nsIWebBrowserFocus.h"
37 #include "nsIClipboardCommands.h"
39 GeckoFrame::GeckoFrame() :
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
)
57 bool GeckoFrame::SetupDefaultGeckoWindow()
59 mGeckoWnd
= (GeckoWindow
*) FindWindowById(XRCID("gecko"), this);
62 return SetupGeckoWindow(mGeckoWnd
, this, getter_AddRefs(mWebBrowser
));
65 bool GeckoFrame::SetupGeckoWindow(GeckoWindow
*aGeckoWindow
, GeckoContainerUI
*aUI
, nsIWebBrowser
**aWebBrowser
) const
67 if (!aGeckoWindow
|| !aUI
)
70 GeckoContainer
*geckoContainer
= new GeckoContainer(aUI
);
74 mGeckoWnd
->SetGeckoContainer(geckoContainer
);
76 PRUint32 aChromeFlags
= nsIWebBrowserChrome::CHROME_ALL
;
77 geckoContainer
->SetChromeFlags(aChromeFlags
);
78 geckoContainer
->SetParent(nsnull
);
79 wxSize size
= mGeckoWnd
->GetClientSize();
82 geckoContainer
->CreateBrowser(0, 0, size
.GetWidth(), size
.GetHeight(),
83 (nativeWindow
) aGeckoWindow
->GetHWND(), aWebBrowser
);
85 nsCOMPtr
<nsIBaseWindow
> webBrowserAsWin
= do_QueryInterface(*aWebBrowser
);
88 webBrowserAsWin
->SetVisibility(PR_TRUE
);
94 void GeckoFrame::OnActivate(wxActivateEvent
&event
)
96 nsCOMPtr
<nsIWebBrowserFocus
> focus(do_GetInterface(mWebBrowser
));
99 if (event
.GetActive())
104 wxFrame::OnActivate(event
);
107 void GeckoFrame::OnEditCut(wxCommandEvent
&event
)
109 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
111 clipCmds
->CutSelection();
114 void GeckoFrame::OnUpdateEditCut(wxUpdateUIEvent
&event
)
116 PRBool canCut
= PR_FALSE
;
117 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
119 clipCmds
->CanCutSelection(&canCut
);
120 event
.Enable(canCut
? true : false);
123 void GeckoFrame::OnEditCopy(wxCommandEvent
&event
)
125 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
127 clipCmds
->CopySelection();
130 void GeckoFrame::OnUpdateEditCopy(wxUpdateUIEvent
&event
)
132 PRBool canCopy
= PR_FALSE
;
133 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
135 clipCmds
->CanCopySelection(&canCopy
);
136 event
.Enable(canCopy
? true : false);
139 void GeckoFrame::OnEditPaste(wxCommandEvent
&event
)
141 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
146 void GeckoFrame::OnUpdateEditPaste(wxUpdateUIEvent
&event
)
148 PRBool canPaste
= PR_FALSE
;
149 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
151 clipCmds
->CanPaste(&canPaste
);
152 event
.Enable(canPaste
? true : false);
155 void GeckoFrame::OnEditSelectAll(wxCommandEvent
&event
)
157 nsCOMPtr
<nsIClipboardCommands
> clipCmds
= do_GetInterface(mWebBrowser
);
159 clipCmds
->SelectAll();
162 ///////////////////////////////////////////////////////////////////////////////
163 // GeckoContainerUI overrides
165 void GeckoFrame::SetFocus()
167 mGeckoWnd
->SetFocus();