Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / embedding / tests / wxEmbed / EmbedApp.cpp
blob6e283b1cdcc0e180ef03d2b42092aa07f3e37e42
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 "nsIProfile.h"
34 #include "nsIWindowWatcher.h"
35 #include "nsMemory.h"
36 #include "nsEmbedString.h"
38 #include "BrowserFrame.h"
39 #include "MailFrame.h"
40 #include "ChatFrame.h"
41 #include "EditorFrame.h"
43 #include "GeckoProtocolHandler.h"
44 #include "GeckoWindowCreator.h"
46 class FooCallback : public GeckoChannelCallback
48 public:
49 virtual nsresult GetData(
50 nsIURI *aURI,
51 nsIChannel *aChannel,
52 nsACString &aContentType,
53 void **aData,
54 PRUint32 *aSize)
56 nsCAutoString spec;
57 nsCAutoString txt("<html><body>Hello, your URL was \'");
58 aURI->GetSpec(spec);
59 txt.Append(spec);
60 txt.Append("\'</body></html>");
61 aContentType.Assign("text/html");
63 size_t size = txt.Length();
64 *aData = (void *) nsMemory::Alloc(size + 1);
65 if (!*aData)
66 return NS_ERROR_OUT_OF_MEMORY;
67 memset(*aData, 0, size + 1);
68 memcpy(*aData, txt.get(), size);
69 *aSize = size;
70 return NS_OK;
74 class EmbedApp : public wxApp
76 virtual bool OnInit();
77 virtual int OnExit();
79 DECLARE_EVENT_TABLE()
80 void OnQuit(wxCommandEvent &event);
81 void OnAbout(wxCommandEvent &event);
82 void OnMail(wxCommandEvent &event);
83 void OnChat(wxCommandEvent &event);
84 void OnEditor(wxCommandEvent &event);
87 BEGIN_EVENT_TABLE(EmbedApp, wxApp)
88 EVT_MENU(XRCID("menu_quit"), EmbedApp::OnQuit)
89 EVT_MENU(XRCID("menu_about"), EmbedApp::OnAbout)
90 EVT_MENU(XRCID("menu_mail"), EmbedApp::OnMail)
91 EVT_MENU(XRCID("menu_chat"), EmbedApp::OnChat)
92 EVT_MENU(XRCID("menu_editor"), EmbedApp::OnEditor)
93 END_EVENT_TABLE()
95 ///////////////////////////////////////////////////////////////////////////////
97 IMPLEMENT_APP(EmbedApp)
99 bool EmbedApp::OnInit()
101 wxImage::AddHandler(new wxGIFHandler);
102 wxXmlResource::Get()->InitAllHandlers();
103 InitXmlResource();
105 if (NS_FAILED(NS_InitEmbedding(nsnull, nsnull)))
107 return FALSE;
110 nsresult rv;
111 nsCOMPtr<nsIProfile> profileService =
112 do_GetService(NS_PROFILE_CONTRACTID, &rv);
113 rv = profileService->CreateNewProfile(L"wxEmbed", nsnull, nsnull, PR_FALSE);
114 if (NS_FAILED(rv)) return FALSE;
115 rv = profileService->SetCurrentProfile(L"wxEmbed");
116 if (NS_FAILED(rv)) return FALSE;
118 GeckoProtocolHandler::RegisterHandler("foo", "Test handler", new FooCallback);
120 // Register a window creator for popups
121 GeckoWindowCreator *creatorCallback = new GeckoWindowCreator();
122 if (creatorCallback)
124 nsCOMPtr<nsIWindowCreator> windowCreator(static_cast<nsIWindowCreator *>(creatorCallback));
125 if (windowCreator)
127 nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
128 if (wwatch)
130 wwatch->SetWindowCreator(windowCreator);
135 // Create the main frame window
136 BrowserFrame* frame = new BrowserFrame(NULL);
137 frame->Show(TRUE);
138 // frame->OnBrowserHome(wxCommandEvent());
140 SetTopWindow(frame);
142 return TRUE;
145 int EmbedApp::OnExit()
147 // Shutdown the profile
148 nsresult rv;
149 nsCOMPtr<nsIProfile> profileService =
150 do_GetService(NS_PROFILE_CONTRACTID, &rv);
151 if (NS_SUCCEEDED(rv))
153 profileService->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST);
155 NS_TermEmbedding();
157 return 0;
160 void EmbedApp::OnQuit(wxCommandEvent & WXUNUSED(event))
162 wxFrame * frame = NULL;
165 do {
166 frame = (wxFrame *) wxWindow::FindWindowByName("browser", NULL);;
167 if (frame)
168 frame->Close(TRUE);
169 } while (frame);
170 frame = (wxFrame *) wxWindow::FindWindowByName("mail", NULL);;
171 if (frame)
172 frame->Close(TRUE);
173 frame = (wxFrame *) wxWindow::FindWindowByName("editor", NULL);;
174 if (frame)
175 frame->Close(TRUE);
176 frame = (wxFrame *) wxWindow::FindWindowByName("chat", NULL);;
177 if (frame)
178 frame->Close(TRUE);
182 GetTopWindow()->Close(TRUE);
185 void EmbedApp::OnAbout(wxCommandEvent & WXUNUSED(event))
187 (void)wxMessageBox(_T("wxEmbed"), _T("About wxEmbed"));
190 void EmbedApp::OnMail(wxCommandEvent & WXUNUSED(event))
192 // Create the mail frame window
193 MailFrame * frame = (MailFrame *) wxWindow::FindWindowByName("mail", NULL);;
194 if (!frame)
195 frame = new MailFrame(NULL);
196 if (frame)
197 frame->Show(TRUE);
200 void EmbedApp::OnChat(wxCommandEvent & WXUNUSED(event))
202 ChatFrame * frame = (ChatFrame *) wxWindow::FindWindowByName("chat", NULL);
203 if (!frame)
204 frame = new ChatFrame(NULL);
205 if (frame)
206 frame->Show(TRUE);
209 void EmbedApp::OnEditor(wxCommandEvent & WXUNUSED(event))
211 EditorFrame * frame = (EditorFrame *) wxWindow::FindWindowByName("editor", NULL);
212 if (!frame)
213 frame = new EditorFrame(NULL);
214 if (frame)
215 frame->Show(TRUE);