]> git.saurik.com Git - wxWidgets.git/blob - samples/web/web.cpp
Add a new event type for new window creation, document and implement under MSW. Updat...
[wxWidgets.git] / samples / web / web.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxiepanel.cpp
3 // Purpose: wxBetterHTMLControl test
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include <wx/wx.h>
11 #include <wx/artprov.h>
12 #include <wx/notifmsg.h>
13 #include <wx/settings.h>
14
15 #if wxUSE_STC
16 #include <wx/stc/stc.h>
17 #else
18 #error "wxStyledTextControl is needed by this sample"
19 #endif
20
21 #include "wx/webview.h"
22 #include "wxlogo.xpm"
23 #include "back.xpm"
24 #include "forward.xpm"
25 #include "stop.xpm"
26 #include "refresh.xpm"
27
28 // --------------------------------------------------------------------------------------------------
29 // SOURCE VIEW FRAME
30 // --------------------------------------------------------------------------------------------------
31 enum
32 {
33 MARGIN_LINE_NUMBERS,
34 //MARGIN_DIVIDER,
35 //MARGIN_FOLDING
36 };
37
38 class SourceViewDialog : public wxDialog
39 {
40 public:
41
42 void onClose(wxCloseEvent& evt)
43 {
44 EndModal( GetReturnCode() );
45 }
46
47 SourceViewDialog(wxWindow* parent, wxString source) :
48 wxDialog(parent, wxID_ANY, "Source Code",
49 wxDefaultPosition, wxSize(700,500),
50 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
51 {
52 wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
53
54 //text->SetLexer(wxSTC_LEX_HTML);
55 text->SetMarginWidth (MARGIN_LINE_NUMBERS, 50);
56 text->StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour (75, 75, 75) );
57 text->StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour (220, 220, 220));
58 text->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
59
60 text->SetWrapMode (wxSTC_WRAP_WORD);
61
62 text->SetText(source);
63
64 text->StyleClearAll();
65 text->SetLexer(wxSTC_LEX_HTML);
66 text->StyleSetForeground (wxSTC_H_DOUBLESTRING, wxColour(255,0,0));
67 text->StyleSetForeground (wxSTC_H_SINGLESTRING, wxColour(255,0,0));
68 text->StyleSetForeground (wxSTC_H_ENTITY, wxColour(255,0,0));
69 text->StyleSetForeground (wxSTC_H_TAG, wxColour(0,150,0));
70 text->StyleSetForeground (wxSTC_H_TAGUNKNOWN, wxColour(0,150,0));
71 text->StyleSetForeground (wxSTC_H_ATTRIBUTE, wxColour(0,0,150));
72 text->StyleSetForeground (wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0,0,150));
73 text->StyleSetForeground (wxSTC_H_COMMENT, wxColour(150,150,150));
74
75
76 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
77 sizer->Add(text, 1, wxEXPAND);
78 SetSizer(sizer);
79
80 Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(SourceViewDialog::onClose), NULL, this);
81 }
82
83
84 };
85
86 // --------------------------------------------------------------------------------------------------
87 // MAIN BROWSER CLASS
88 // --------------------------------------------------------------------------------------------------
89 class wxMiniApp : public wxApp
90 {
91 wxTextCtrl* url;
92 wxWebView* m_browser_ctrl;
93 wxFrame* frame;
94
95 wxToolBarToolBase* back;
96 wxToolBarToolBase* forward;
97 wxToolBarToolBase* stop;
98 wxToolBarToolBase* reload;
99 wxToolBarToolBase* tools;
100
101 wxMenu* toolsMenu;
102 wxMenuItem* tinySize;
103 wxMenuItem* smallSize;
104 wxMenuItem* mediumSize;
105 wxMenuItem* largeSize;
106 wxMenuItem* largestSize;
107
108 //wxMenuItem* offlineMode;
109 //wxMenuItem* onlineMode;
110
111 wxLogWindow* logging;
112 wxToolBar* m_toolbar;
113
114 wxTimer* m_timer;
115 int m_animation_angle;
116
117 wxPanel* m_notification_panel;
118 wxStaticText* m_notification_text;
119
120 public:
121 // function called at the application initialization
122 virtual bool OnInit();
123
124 /**
125 * Implement timer to display the loading animation (OK, I admit this is totally irrelevant to
126 * the HTML control being demonstrated here, but it's fun ;)
127 */
128 void onAnimationTimer(wxTimerEvent& evt)
129 {
130 m_animation_angle += 15;
131 if (m_animation_angle > 360) m_animation_angle -= 360;
132
133 wxBitmap image(32, 32);
134
135 {
136 wxMemoryDC dc;
137 dc.SelectObject(image);
138 dc.SetBackground(wxBrush(wxColour(255,0,255)));
139 dc.Clear();
140
141 if (m_animation_angle >= 0 && m_animation_angle <= 180)
142 {
143 dc.SetBrush(*wxYELLOW_BRUSH);
144 dc.SetPen(*wxYELLOW_PEN);
145 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
146 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
147 }
148
149 dc.DrawBitmap(wxBitmap(wxlogo_xpm), 0, 0, true);
150
151 if (m_animation_angle > 180)
152 {
153 dc.SetBrush(*wxYELLOW_BRUSH);
154 dc.SetPen(*wxYELLOW_PEN);
155 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
156 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
157 }
158 }
159
160 image.SetMask(new wxMask(image, wxColour(255,0,255)));
161 m_toolbar->SetToolNormalBitmap(tools->GetId(), image);
162 }
163
164 /**
165 * Method that retrieves the current state from the web control and updates the GUI
166 * the reflect this current state.
167 */
168 void updateState()
169 {
170 m_toolbar->EnableTool( back->GetId(), m_browser_ctrl->CanGoBack() );
171 m_toolbar->EnableTool( forward->GetId(), m_browser_ctrl->CanGoForward() );
172
173 if (m_browser_ctrl->IsBusy())
174 {
175 //tools->SetLabel(_("Loading..."));
176
177 if (m_timer == NULL)
178 {
179 m_timer = new wxTimer(this);
180 this->Connect(wxEVT_TIMER, wxTimerEventHandler(wxMiniApp::onAnimationTimer), NULL, this);
181 }
182 m_timer->Start(100); // start animation timer
183
184 m_toolbar->EnableTool( stop->GetId(), true );
185 }
186 else
187 {
188 if (m_timer != NULL) m_timer->Stop(); // stop animation timer
189
190 //tools->SetLabel(_("Tools"));
191 m_toolbar->SetToolNormalBitmap(tools->GetId(), wxBitmap(wxlogo_xpm));
192 m_toolbar->EnableTool( stop->GetId(), false );
193 }
194
195 frame->SetTitle( m_browser_ctrl->GetCurrentTitle() );
196 url->SetValue( m_browser_ctrl->GetCurrentURL() );
197 }
198
199 /**
200 * Callback invoked when user entered an URL and pressed enter
201 */
202 void onUrl(wxCommandEvent& evt)
203 {
204 if (m_notification_panel->IsShown())
205 {
206 m_notification_panel->Hide();
207 frame->Layout();
208 }
209
210 m_browser_ctrl->LoadUrl( url->GetValue() );
211 updateState();
212 }
213
214 /**
215 * Callback invoked when user pressed the "back" button
216 */
217 void onBack(wxCommandEvent& evt)
218 {
219 // First, hide notification panel if it was shown
220 if (m_notification_panel->IsShown())
221 {
222 m_notification_panel->Hide();
223 frame->Layout();
224 }
225
226 m_browser_ctrl->GoBack();
227 updateState();
228 }
229
230 /**
231 * Callback invoked when user pressed the "forward" button
232 */
233 void onForward(wxCommandEvent& evt)
234 {
235 // First, hide notification panel if it was shown
236 if (m_notification_panel->IsShown())
237 {
238 m_notification_panel->Hide();
239 frame->Layout();
240 }
241
242 m_browser_ctrl->GoForward();
243 updateState();
244 }
245
246 /**
247 * Callback invoked when user pressed the "stop" button
248 */
249 void onStop(wxCommandEvent& evt)
250 {
251 m_browser_ctrl->Stop();
252 updateState();
253 }
254
255 /**
256 * Callback invoked when user pressed the "reload" button
257 */
258 void onReload(wxCommandEvent& evt)
259 {
260 // First, hide notification panel if it was shown
261 if (m_notification_panel->IsShown())
262 {
263 m_notification_panel->Hide();
264 frame->Layout();
265 }
266
267 m_browser_ctrl->Reload();
268 updateState();
269 }
270
271 /**
272 * Callback invoked when there is a request to load a new page (for instance
273 * when the user clicks a link)
274 */
275 void onNavigationRequest(wxWebNavigationEvent& evt)
276 {
277 // First, hide notification panel if it was shown
278 if (m_notification_panel->IsShown())
279 {
280 m_notification_panel->Hide();
281 frame->Layout();
282 }
283
284 wxLogMessage("%s", "Navigation request to '" + evt.GetHref() + "' (target='" +
285 evt.GetTarget() + "')");
286
287 wxASSERT(m_browser_ctrl->IsBusy());
288
289 // Uncomment this to see how to block navigation requests
290 //int answer = wxMessageBox("Proceed with navigation to '" + evt.GetHref() + "'?",
291 // "Proceed with navigation?", wxYES_NO );
292 //if (answer != wxYES)
293 //{
294 // evt.Veto();
295 //}
296 updateState();
297 }
298
299 /**
300 * Callback invoked when a navigation request was accepted
301 */
302 void onNavigationComplete(wxWebNavigationEvent& evt)
303 {
304 wxLogMessage("%s", "Navigation complete; url='" + evt.GetHref() + "'");
305 updateState();
306 }
307
308 /**
309 * Callback invoked when a page is finished loading
310 */
311 void onDocumentLoaded(wxWebNavigationEvent& evt)
312 {
313 wxLogMessage("%s", "Document loaded; url='" + evt.GetHref() + "'");
314 updateState();
315
316 m_browser_ctrl->GetZoom();
317 }
318
319 /**
320 * On new window, we veto to stop extra windows appearing
321 */
322 void onNewWindow(wxWebNavigationEvent& evt)
323 {
324 wxLogMessage("%s", "New window; url='" + evt.GetHref() + "'");
325 evt.Veto();
326
327 updateState();
328 }
329
330 /**
331 * Invoked when user selects the "View Source" menu item
332 */
333 void onViewSourceRequest(wxCommandEvent& evt)
334 {
335 SourceViewDialog dlg(frame, m_browser_ctrl->GetPageSource());
336 dlg.Center();
337 dlg.ShowModal();
338 }
339
340 /**
341 * Invoked when user selects the "Menu" item
342 */
343 void onToolsClicked(wxCommandEvent& evt)
344 {
345 tinySize->Check(false);
346 smallSize->Check(false);
347 mediumSize->Check(false);
348 largeSize->Check(false);
349 largestSize->Check(false);
350
351 wxWebViewZoom zoom = m_browser_ctrl->GetZoom();
352 switch (zoom)
353 {
354 case wxWEB_VIEW_ZOOM_TINY:
355 tinySize->Check();
356 break;
357 case wxWEB_VIEW_ZOOM_SMALL:
358 smallSize->Check();
359 break;
360 case wxWEB_VIEW_ZOOM_MEDIUM:
361 mediumSize->Check();
362 break;
363 case wxWEB_VIEW_ZOOM_LARGE:
364 largeSize->Check();
365 break;
366 case wxWEB_VIEW_ZOOM_LARGEST:
367 largestSize->Check();
368 break;
369 }
370
371 // bool IsOfflineMode();
372 // void SetOfflineMode(bool offline);
373
374 //offlineMode->Check(false);
375 //onlineMode->Check(false);
376 //const bool offline = m_browser_ctrl->IsOfflineMode();
377 //if (offline) offlineMode->Check();
378 //else onlineMode->Check();
379
380 wxPoint position = frame->ScreenToClient( wxGetMousePosition() );
381 frame->PopupMenu(toolsMenu, position.x, position.y);
382 }
383
384 /**
385 * Invoked when user selects the zoom size in the menu
386 */
387 void onSetZoom(wxCommandEvent& evt)
388 {
389 if (evt.GetId() == tinySize->GetId())
390 {
391 m_browser_ctrl->SetZoom(wxWEB_VIEW_ZOOM_TINY);
392 }
393 else if (evt.GetId() == smallSize->GetId())
394 {
395 m_browser_ctrl->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
396 }
397 else if (evt.GetId() == mediumSize->GetId())
398 {
399 m_browser_ctrl->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
400 }
401 else if (evt.GetId() == largeSize->GetId())
402 {
403 m_browser_ctrl->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
404 }
405 else if (evt.GetId() == largestSize->GetId())
406 {
407 m_browser_ctrl->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
408 }
409 else
410 {
411 wxASSERT(false);
412 }
413 }
414
415 /*
416 void onChangeOnlineMode(wxCommandEvent& evt)
417 {
418 if (evt.GetId() == offlineMode->GetId())
419 {
420 m_browser_ctrl->SetOfflineMode(true);
421 m_browser_ctrl->SetPage("<html><body><h1>You are now in offline mode.</h1></body></html>");
422 }
423 else if (evt.GetId() == onlineMode->GetId())
424 {
425 m_browser_ctrl->SetOfflineMode(false);
426 }
427 else
428 {
429 wxASSERT(false);
430 }
431 }
432 */
433
434 /**
435 * Callback invoked when a loading error occurs
436 */
437 void onError(wxWebNavigationEvent& evt)
438 {
439 wxString errorCategory;
440 switch (evt.GetInt())
441 {
442 case wxWEB_NAV_ERR_CONNECTION:
443 errorCategory = "wxWEB_NAV_ERR_CONNECTION";
444 break;
445
446 case wxWEB_NAV_ERR_CERTIFICATE:
447 errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
448 break;
449
450 case wxWEB_NAV_ERR_AUTH:
451 errorCategory = "wxWEB_NAV_ERR_AUTH";
452 break;
453
454 case wxWEB_NAV_ERR_SECURITY:
455 errorCategory = "wxWEB_NAV_ERR_SECURITY";
456 break;
457
458 case wxWEB_NAV_ERR_NOT_FOUND:
459 errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
460 break;
461
462 case wxWEB_NAV_ERR_REQUEST:
463 errorCategory = "wxWEB_NAV_ERR_REQUEST";
464 break;
465
466 case wxWEB_NAV_ERR_USER_CANCELLED:
467 errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
468 break;
469
470 case wxWEB_NAV_ERR_OTHER:
471 errorCategory = "wxWEB_NAV_ERR_OTHER";
472 break;
473 }
474
475 wxLogMessage("Error; url='" + evt.GetHref() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
476
477 // show the notification panel
478 m_notification_text->SetLabel(_("An error occurred loading ") + evt.GetHref() + "\n" +
479 "'" + errorCategory + "' (" + evt.GetString() + ")");
480 m_notification_panel->Layout();
481 m_notification_panel->GetSizer()->SetSizeHints(m_notification_panel);
482 m_notification_panel->Show();
483 frame->Layout();
484
485 updateState();
486 }
487
488 /**
489 * Invoked when user clicks "Hide" in the notification panel
490 */
491 void onHideNotifBar(wxCommandEvent& evt)
492 {
493 m_notification_panel->Hide();
494 frame->Layout();
495 }
496
497 void onClose(wxCloseEvent& evt)
498 {
499 frame->Destroy();
500 }
501
502 void onQuitMenu(wxCommandEvent& evt)
503 {
504 frame->Destroy();
505 }
506
507 /**
508 * Invoked when user selects "Print" from the menu
509 */
510 void onPrint(wxCommandEvent& evt)
511 {
512 m_browser_ctrl->Print();
513 }
514 };
515
516 IMPLEMENT_APP(wxMiniApp);
517
518 bool wxMiniApp::OnInit()
519 {
520 m_timer = NULL;
521 m_animation_angle = 0;
522
523 frame = new wxFrame( NULL, -1, _("wxBetterHTMLControl Browser Example"), wxDefaultPosition, wxSize(800, 600) );
524
525 // wx has a default mechanism to expand the only control of a frame; but since this mechanism
526 // does not involve sizers, invoking ->Layout on the frame does not udpate the layout which is
527 // not good.
528 wxBoxSizer* expandSizer = new wxBoxSizer(wxHORIZONTAL);
529 wxPanel* mainpane = new wxPanel(frame, wxID_ANY);
530 expandSizer->Add(mainpane, 1, wxEXPAND);
531 frame->SetSizer(expandSizer);
532
533 wxLog::SetLogLevel(wxLOG_Max);
534 logging = new wxLogWindow(frame, _("Logging"));
535 wxLog::SetLogLevel(wxLOG_Max);
536
537 // ---- Create the Tools menu
538 toolsMenu = new wxMenu();
539 wxMenuItem* print = toolsMenu->Append(wxID_ANY , _("Print"));
540 wxMenuItem* viewSource = toolsMenu->Append(wxID_ANY , _("View Source"));
541 toolsMenu->AppendSeparator();
542 tinySize = toolsMenu->AppendCheckItem(wxID_ANY, _("Tiny"));
543 smallSize = toolsMenu->AppendCheckItem(wxID_ANY, _("Small"));
544 mediumSize = toolsMenu->AppendCheckItem(wxID_ANY, _("Medium"));
545 largeSize = toolsMenu->AppendCheckItem(wxID_ANY, _("Large"));
546 largestSize = toolsMenu->AppendCheckItem(wxID_ANY, _("Largest"));
547 //toolsMenu->AppendSeparator();
548 //offlineMode = toolsMenu->AppendCheckItem(wxID_ANY, _("Offline Mode"));
549 //onlineMode = toolsMenu->AppendCheckItem(wxID_ANY, _("Online Mode"));
550
551 // ---- Create the Toolbar
552 m_toolbar = frame->CreateToolBar(/*wxNO_BORDER |*/ wxTB_TEXT);
553 m_toolbar->SetToolBitmapSize(wxSize(32, 32));
554
555 back = m_toolbar->AddTool(wxID_ANY, _("Back"), wxBitmap(back_xpm));
556 forward = m_toolbar->AddTool(wxID_ANY, _("Forward"), wxBitmap(forward_xpm));
557 stop = m_toolbar->AddTool(wxID_ANY, _("Stop"), wxBitmap(stop_xpm));
558 reload = m_toolbar->AddTool(wxID_ANY, _("Reload"), wxBitmap(refresh_xpm));
559
560 url = new wxTextCtrl(m_toolbar, wxID_ANY, wxT("http://www.google.com"),
561 wxDefaultPosition, wxSize(400, -1), wxTE_PROCESS_ENTER );
562 m_toolbar->AddControl(url, _("URL"));
563 tools = m_toolbar->AddTool(wxID_ANY, _("Menu"), wxBitmap(wxlogo_xpm));
564 //m_toolbar->SetDropdownMenu(tools->GetId(), toolsMenu);
565
566 m_toolbar->Realize();
567
568 m_toolbar->Connect(back->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
569 wxCommandEventHandler(wxMiniApp::onBack), NULL, this );
570 m_toolbar->Connect(forward->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
571 wxCommandEventHandler(wxMiniApp::onForward), NULL, this );
572 m_toolbar->Connect(stop->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
573 wxCommandEventHandler(wxMiniApp::onStop), NULL, this );
574 m_toolbar->Connect(reload->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
575 wxCommandEventHandler(wxMiniApp::onReload), NULL, this );
576 m_toolbar->Connect(tools->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
577 wxCommandEventHandler(wxMiniApp::onToolsClicked), NULL, this );
578
579 url->Connect(url->GetId(), wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(wxMiniApp::onUrl), NULL, this );
580
581
582 frame->Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
583 wxCommandEventHandler(wxMiniApp::onViewSourceRequest), NULL, this );
584 frame->Connect(print->GetId(), wxEVT_COMMAND_MENU_SELECTED,
585 wxCommandEventHandler(wxMiniApp::onPrint), NULL, this );
586
587 frame->Connect(tinySize->GetId(), wxEVT_COMMAND_MENU_SELECTED,
588 wxCommandEventHandler(wxMiniApp::onSetZoom), NULL, this );
589 frame->Connect(smallSize->GetId(), wxEVT_COMMAND_MENU_SELECTED,
590 wxCommandEventHandler(wxMiniApp::onSetZoom), NULL, this );
591 frame->Connect(mediumSize->GetId(), wxEVT_COMMAND_MENU_SELECTED,
592 wxCommandEventHandler(wxMiniApp::onSetZoom), NULL, this );
593 frame->Connect(largeSize->GetId(), wxEVT_COMMAND_MENU_SELECTED,
594 wxCommandEventHandler(wxMiniApp::onSetZoom), NULL, this );
595 frame->Connect(largestSize->GetId(), wxEVT_COMMAND_MENU_SELECTED,
596 wxCommandEventHandler(wxMiniApp::onSetZoom), NULL, this );
597
598 // ---- Create the web view
599 m_browser_ctrl = wxWebView::New(mainpane, wxID_ANY);
600
601 // ---- Create the notification panel
602 {
603 wxBoxSizer* notification_sizer = new wxBoxSizer(wxHORIZONTAL);
604 m_notification_panel = new wxPanel(mainpane, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE);
605 m_notification_text = new wxStaticText(m_notification_panel, wxID_ANY, "[No message]");
606 notification_sizer->Add( new wxStaticBitmap(m_notification_panel, wxID_ANY,
607 wxArtProvider::GetBitmap(wxART_WARNING, wxART_OTHER , wxSize(48, 48))),
608 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
609 notification_sizer->Add(m_notification_text, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 5);
610 wxButton* hideNotif = new wxButton(m_notification_panel, wxID_ANY, _("Hide"));
611 notification_sizer->Add(hideNotif, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
612 m_notification_panel->SetSizer(notification_sizer);
613 m_notification_panel->SetBackgroundColour(wxColor(255,225,110));
614 m_notification_panel->Hide();
615 hideNotif->Connect(hideNotif->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
616 wxCommandEventHandler(wxMiniApp::onHideNotifBar), NULL, this);
617 }
618
619 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
620 sizer->Add(m_notification_panel, 0, wxEXPAND | wxALL, 5);
621 sizer->Add(m_browser_ctrl, 1, wxEXPAND | wxALL, 5);
622
623 mainpane->SetSizer(sizer);
624 frame->Layout();
625 frame->Center();
626 frame->Show();
627
628 m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
629 wxWebNavigationEventHandler(wxMiniApp::onNavigationRequest), NULL, this);
630
631 m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
632 wxWebNavigationEventHandler(wxMiniApp::onNavigationComplete), NULL, this);
633
634 m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
635 wxWebNavigationEventHandler(wxMiniApp::onDocumentLoaded), NULL, this);
636
637 m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
638 wxWebNavigationEventHandler(wxMiniApp::onError), NULL, this);
639
640 m_browser_ctrl->Connect(m_browser_ctrl->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
641 wxWebNavigationEventHandler(wxMiniApp::onNewWindow), NULL, this);
642
643 frame->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(wxMiniApp::onClose), NULL, this);
644 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxMiniApp::onQuitMenu), NULL, this);
645
646 // You can test different zoom types (if supported by the backend)
647 // if (m_browser_ctrl->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT))
648 // m_browser_ctrl->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT);
649
650 SetTopWindow(frame);
651 frame->Layout();
652
653 return true;
654 }