]> git.saurik.com Git - wxWidgets.git/blob - samples/web/web.cpp
Add new clipboard api and support for it in the ie backend. Also extend the sample...
[wxWidgets.git] / samples / web / web.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: web.cpp
3 // Purpose: wxWebView sample
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24
25 #include <wx/artprov.h>
26 #include <wx/notifmsg.h>
27 #include <wx/settings.h>
28 #include <wx/webview.h>
29 #include <wx/infobar.h>
30
31 #if !defined(__WXMSW__) && !defined(__WXPM__)
32 #include "../sample.xpm"
33 #endif
34
35 #if wxUSE_STC
36 #include <wx/stc/stc.h>
37 #else
38 #error "wxStyledTextControl is needed by this sample"
39 #endif
40
41 #include "stop.xpm"
42 #include "refresh.xpm"
43 #include "wxlogo.xpm"
44
45 class WebApp : public wxApp
46 {
47 public:
48 virtual bool OnInit();
49 };
50
51 class WebFrame : public wxFrame
52 {
53 public:
54 WebFrame();
55
56 void OnAnimationTimer(wxTimerEvent& evt);
57 void UpdateState();
58 void OnUrl(wxCommandEvent& evt);
59 void OnBack(wxCommandEvent& evt);
60 void OnForward(wxCommandEvent& evt);
61 void OnStop(wxCommandEvent& evt);
62 void OnReload(wxCommandEvent& evt);
63 void OnClearHistory(wxCommandEvent& evt);
64 void OnEnableHistory(wxCommandEvent& evt);
65 void OnNavigationRequest(wxWebNavigationEvent& evt);
66 void OnNavigationComplete(wxWebNavigationEvent& evt);
67 void OnDocumentLoaded(wxWebNavigationEvent& evt);
68 void OnNewWindow(wxWebNavigationEvent& evt);
69 void OnViewSourceRequest(wxCommandEvent& evt);
70 void OnToolsClicked(wxCommandEvent& evt);
71 void OnSetZoom(wxCommandEvent& evt);
72 void OnError(wxWebNavigationEvent& evt);
73 void OnPrint(wxCommandEvent& evt);
74 void OnCut(wxCommandEvent& evt);
75 void OnCopy(wxCommandEvent& evt);
76 void OnPaste(wxCommandEvent& evt);
77
78 private:
79 wxTextCtrl* m_url;
80 wxWebView* m_browser;
81
82 wxToolBar* m_toolbar;
83 wxToolBarToolBase* m_toolbar_back;
84 wxToolBarToolBase* m_toolbar_forward;
85 wxToolBarToolBase* m_toolbar_stop;
86 wxToolBarToolBase* m_toolbar_reload;
87 wxToolBarToolBase* m_toolbar_tools;
88
89 wxMenu* m_tools_menu;
90 wxMenuItem* m_tools_tiny;
91 wxMenuItem* m_tools_small;
92 wxMenuItem* m_tools_medium;
93 wxMenuItem* m_tools_large;
94 wxMenuItem* m_tools_largest;
95 wxMenuItem* m_tools_handle_navigation;
96 wxMenuItem* m_tools_handle_new_window;
97 wxMenuItem* m_tools_enable_history;
98 wxMenuItem* m_edit_cut;
99 wxMenuItem* m_edit_copy;
100 wxMenuItem* m_edit_paste;
101
102 wxTimer* m_timer;
103 int m_animation_angle;
104
105 wxInfoBar *m_info;
106 wxStaticText* m_info_text;
107 };
108
109 class SourceViewDialog : public wxDialog
110 {
111 public:
112 SourceViewDialog(wxWindow* parent, wxString source);
113 };
114
115 IMPLEMENT_APP(WebApp)
116
117 // ============================================================================
118 // implementation
119 // ============================================================================
120
121 bool WebApp::OnInit()
122 {
123 if ( !wxApp::OnInit() )
124 return false;
125
126 WebFrame *frame = new WebFrame();
127 frame->Show();
128
129 return true;
130 }
131
132 WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
133 {
134 // set the frame icon
135 SetIcon(wxICON(sample));
136 SetTitle("wxWebView Sample");
137
138 m_timer = NULL;
139 m_animation_angle = 0;
140
141
142 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
143
144 // Create the toolbar
145 m_toolbar = CreateToolBar(wxTB_TEXT);
146 m_toolbar->SetToolBitmapSize(wxSize(32, 32));
147
148 wxBitmap back = wxArtProvider::GetBitmap(wxART_GO_BACK , wxART_TOOLBAR);
149 wxBitmap forward = wxArtProvider::GetBitmap(wxART_GO_FORWARD , wxART_TOOLBAR);
150 #ifdef __WXGTK__
151 wxBitmap stop = wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR);
152 #else
153 wxBitmap stop = wxBitmap(stop_xpm);
154 #endif
155 #ifdef __WXGTK__
156 wxBitmap refresh = wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR);
157 #else
158 wxBitmap refresh = wxBitmap(refresh_xpm);
159 #endif
160
161 m_toolbar_back = m_toolbar->AddTool(wxID_ANY, _("Back"), back);
162 m_toolbar_forward = m_toolbar->AddTool(wxID_ANY, _("Forward"), forward);
163 m_toolbar_stop = m_toolbar->AddTool(wxID_ANY, _("Stop"), stop);
164 m_toolbar_reload = m_toolbar->AddTool(wxID_ANY, _("Reload"), refresh);
165 m_url = new wxTextCtrl(m_toolbar, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_PROCESS_ENTER );
166 m_toolbar->AddControl(m_url, _("URL"));
167 m_toolbar_tools = m_toolbar->AddTool(wxID_ANY, _("Menu"), wxBitmap(wxlogo_xpm));
168
169 m_toolbar->Realize();
170
171 // Create the info panel
172 m_info = new wxInfoBar(this);
173 topsizer->Add(m_info, wxSizerFlags().Expand());
174
175 // Create the webview
176 m_browser = wxWebView::New(this, wxID_ANY, "http://www.wxwidgets.org");
177 topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
178
179 SetSizer(topsizer);
180
181 //Set a more sensible size for web browsing
182 SetSize(wxSize(800, 600));
183
184 // Create a log window
185 new wxLogWindow(this, _("Logging"));
186
187 // Create the Tools menu
188 m_tools_menu = new wxMenu();
189 wxMenuItem* print = m_tools_menu->Append(wxID_ANY , _("Print"));
190 wxMenuItem* viewSource = m_tools_menu->Append(wxID_ANY , _("View Source"));
191 m_tools_menu->AppendSeparator();
192 m_tools_tiny = m_tools_menu->AppendCheckItem(wxID_ANY, _("Tiny"));
193 m_tools_small = m_tools_menu->AppendCheckItem(wxID_ANY, _("Small"));
194 m_tools_medium = m_tools_menu->AppendCheckItem(wxID_ANY, _("Medium"));
195 m_tools_large = m_tools_menu->AppendCheckItem(wxID_ANY, _("Large"));
196 m_tools_largest = m_tools_menu->AppendCheckItem(wxID_ANY, _("Largest"));
197 m_tools_menu->AppendSeparator();
198 m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation"));
199 m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
200 m_tools_menu->AppendSeparator();
201 wxMenuItem* clearhist = m_tools_menu->Append(wxID_ANY, _("Clear History"));
202 m_tools_enable_history = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
203
204 //Create an editing menu
205 wxMenu* editmenu = new wxMenu();
206 m_edit_cut = editmenu->Append(wxID_ANY, _("Cut"));
207 m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
208 m_edit_paste = editmenu->Append(wxID_ANY, _("Paste"));
209
210 m_tools_menu->AppendSeparator();
211 m_tools_menu->AppendSubMenu(editmenu, "Edit");
212
213 //By default we want to handle navigation and new windows
214 m_tools_handle_navigation->Check();
215 m_tools_handle_new_window->Check();
216 m_tools_enable_history->Check();
217
218
219 // Connect the toolbar events
220 Connect(m_toolbar_back->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
221 wxCommandEventHandler(WebFrame::OnBack), NULL, this );
222 Connect(m_toolbar_forward->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
223 wxCommandEventHandler(WebFrame::OnForward), NULL, this );
224 Connect(m_toolbar_stop->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
225 wxCommandEventHandler(WebFrame::OnStop), NULL, this );
226 Connect(m_toolbar_reload->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
227 wxCommandEventHandler(WebFrame::OnReload),NULL, this );
228 Connect(m_toolbar_tools->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
229 wxCommandEventHandler(WebFrame::OnToolsClicked), NULL, this );
230
231 Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
232 wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
233
234 // Connect the webview events
235 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
236 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest), NULL, this);
237 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
238 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete), NULL, this);
239 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
240 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
241 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
242 wxWebNavigationEventHandler(WebFrame::OnError), NULL, this);
243 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
244 wxWebNavigationEventHandler(WebFrame::OnNewWindow), NULL, this);
245
246 // Connect the menu events
247 Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
248 wxCommandEventHandler(WebFrame::OnViewSourceRequest), NULL, this );
249 Connect(print->GetId(), wxEVT_COMMAND_MENU_SELECTED,
250 wxCommandEventHandler(WebFrame::OnPrint), NULL, this );
251 Connect(m_tools_tiny->GetId(), wxEVT_COMMAND_MENU_SELECTED,
252 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
253 Connect(m_tools_small->GetId(), wxEVT_COMMAND_MENU_SELECTED,
254 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
255 Connect(m_tools_medium->GetId(), wxEVT_COMMAND_MENU_SELECTED,
256 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
257 Connect(m_tools_large->GetId(), wxEVT_COMMAND_MENU_SELECTED,
258 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
259 Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED,
260 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
261 Connect(clearhist->GetId(), wxEVT_COMMAND_MENU_SELECTED,
262 wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
263 Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
264 wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
265 Connect(m_edit_cut->GetId(), wxEVT_COMMAND_MENU_SELECTED,
266 wxCommandEventHandler(WebFrame::OnCut), NULL, this );
267 Connect(m_edit_copy->GetId(), wxEVT_COMMAND_MENU_SELECTED,
268 wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
269 Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(WebFrame::OnPaste), NULL, this );
271 }
272
273 void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
274 {
275 m_animation_angle += 15;
276 if (m_animation_angle > 360) m_animation_angle -= 360;
277
278 wxBitmap image(24, 24);
279 {
280 wxMemoryDC dc;
281 dc.SelectObject(image);
282 dc.SetBackground(wxBrush(wxColour(255,0,255)));
283 dc.Clear();
284
285 if (m_animation_angle >= 0 && m_animation_angle <= 180)
286 {
287 dc.SetBrush(*wxYELLOW_BRUSH);
288 dc.SetPen(*wxYELLOW_PEN);
289 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
290 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
291 }
292
293 dc.DrawBitmap(wxBitmap(wxlogo_xpm), 0, 0, true);
294
295 if (m_animation_angle > 180)
296 {
297 dc.SetBrush(*wxYELLOW_BRUSH);
298 dc.SetPen(*wxYELLOW_PEN);
299 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
300 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
301 }
302 }
303 image.SetMask(new wxMask(image, wxColour(255,0,255)));
304 m_toolbar->SetToolNormalBitmap(m_toolbar_tools->GetId(), image);
305 }
306
307 /**
308 * Method that retrieves the current state from the web control and updates the GUI
309 * the reflect this current state.
310 */
311 void WebFrame::UpdateState()
312 {
313 m_toolbar->EnableTool( m_toolbar_back->GetId(), m_browser->CanGoBack() );
314 m_toolbar->EnableTool( m_toolbar_forward->GetId(), m_browser->CanGoForward() );
315
316 if (m_browser->IsBusy())
317 {
318 if (m_timer == NULL)
319 {
320 m_timer = new wxTimer(this);
321 this->Connect(wxEVT_TIMER, wxTimerEventHandler(WebFrame::OnAnimationTimer), NULL, this);
322 }
323 m_timer->Start(100); // start animation timer
324
325 m_toolbar->EnableTool( m_toolbar_stop->GetId(), true );
326 }
327 else
328 {
329 if (m_timer != NULL) m_timer->Stop(); // stop animation timer
330 m_toolbar->SetToolNormalBitmap(m_toolbar_tools->GetId(), wxBitmap(wxlogo_xpm));
331 m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
332 }
333
334 SetTitle( m_browser->GetCurrentTitle() );
335 m_url->SetValue( m_browser->GetCurrentURL() );
336 }
337
338 /**
339 * Callback invoked when user entered an URL and pressed enter
340 */
341 void WebFrame::OnUrl(wxCommandEvent& evt)
342 {
343 m_browser->LoadUrl( m_url->GetValue() );
344 UpdateState();
345 }
346
347 /**
348 * Callback invoked when user pressed the "back" button
349 */
350 void WebFrame::OnBack(wxCommandEvent& evt)
351 {
352 m_browser->GoBack();
353 UpdateState();
354 }
355
356 /**
357 * Callback invoked when user pressed the "forward" button
358 */
359 void WebFrame::OnForward(wxCommandEvent& evt)
360 {
361 m_browser->GoForward();
362 UpdateState();
363 }
364
365 /**
366 * Callback invoked when user pressed the "stop" button
367 */
368 void WebFrame::OnStop(wxCommandEvent& evt)
369 {
370 m_browser->Stop();
371 UpdateState();
372 }
373
374 /**
375 * Callback invoked when user pressed the "reload" button
376 */
377 void WebFrame::OnReload(wxCommandEvent& evt)
378 {
379 m_browser->Reload();
380 UpdateState();
381 }
382
383 void WebFrame::OnClearHistory(wxCommandEvent& evt)
384 {
385 m_browser->ClearHistory();
386 UpdateState();
387 }
388
389 void WebFrame::OnEnableHistory(wxCommandEvent& evt)
390 {
391 m_browser->EnableHistory(m_tools_enable_history->IsChecked());
392 UpdateState();
393 }
394
395 void WebFrame::OnCut(wxCommandEvent& evt)
396 {
397 m_browser->Cut();
398 }
399
400 void WebFrame::OnCopy(wxCommandEvent& evt)
401 {
402 m_browser->Copy();
403 }
404
405 void WebFrame::OnPaste(wxCommandEvent& evt)
406 {
407 m_browser->Paste();
408 }
409
410 /**
411 * Callback invoked when there is a request to load a new page (for instance
412 * when the user clicks a link)
413 */
414 void WebFrame::OnNavigationRequest(wxWebNavigationEvent& evt)
415 {
416 wxLogMessage("%s", "Navigation request to '" + evt.GetHref() + "' (target='" +
417 evt.GetTarget() + "')");
418
419 wxASSERT(m_browser->IsBusy());
420
421 //If we don't want to handle navigation then veto the event and navigation
422 //will not take place
423 if(!m_tools_handle_navigation->IsChecked())
424 evt.Veto();
425
426 UpdateState();
427 }
428
429 /**
430 * Callback invoked when a navigation request was accepted
431 */
432 void WebFrame::OnNavigationComplete(wxWebNavigationEvent& evt)
433 {
434 wxLogMessage("%s", "Navigation complete; url='" + evt.GetHref() + "'");
435 UpdateState();
436 }
437
438 /**
439 * Callback invoked when a page is finished loading
440 */
441 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent& evt)
442 {
443 wxLogMessage("%s", "Document loaded; url='" + evt.GetHref() + "'");
444 UpdateState();
445 }
446
447 /**
448 * On new window, we veto to stop extra windows appearing
449 */
450 void WebFrame::OnNewWindow(wxWebNavigationEvent& evt)
451 {
452 wxLogMessage("%s", "New window; url='" + evt.GetHref() + "'");
453
454 //If we handle new window events then just load them in this window as we
455 //are a single window browser
456 if(m_tools_handle_new_window->IsChecked())
457 m_browser->LoadUrl(evt.GetHref());
458
459 //We always veto because we handle the event, otherwise under windows a new
460 //internet explorer windowis created
461 evt.Veto();
462
463 UpdateState();
464 }
465
466 /**
467 * Invoked when user selects the "View Source" menu item
468 */
469 void WebFrame::OnViewSourceRequest(wxCommandEvent& evt)
470 {
471 SourceViewDialog dlg(this, m_browser->GetPageSource());
472 dlg.ShowModal();
473 }
474
475 /**
476 * Invoked when user selects the "Menu" item
477 */
478 void WebFrame::OnToolsClicked(wxCommandEvent& evt)
479 {
480 if(m_browser->GetCurrentURL() == "")
481 return;
482
483 m_tools_tiny->Check(false);
484 m_tools_small->Check(false);
485 m_tools_medium->Check(false);
486 m_tools_large->Check(false);
487 m_tools_largest->Check(false);
488
489 wxWebViewZoom zoom = m_browser->GetZoom();
490 switch (zoom)
491 {
492 case wxWEB_VIEW_ZOOM_TINY:
493 m_tools_tiny->Check();
494 break;
495 case wxWEB_VIEW_ZOOM_SMALL:
496 m_tools_small->Check();
497 break;
498 case wxWEB_VIEW_ZOOM_MEDIUM:
499 m_tools_medium->Check();
500 break;
501 case wxWEB_VIEW_ZOOM_LARGE:
502 m_tools_large->Check();
503 break;
504 case wxWEB_VIEW_ZOOM_LARGEST:
505 m_tools_largest->Check();
506 break;
507 }
508
509 m_edit_cut->Enable(m_browser->CanCut());
510 m_edit_copy->Enable(m_browser->CanCopy());
511 m_edit_paste->Enable(m_browser->CanPaste());
512
513 wxPoint position = ScreenToClient( wxGetMousePosition() );
514 PopupMenu(m_tools_menu, position.x, position.y);
515 }
516
517 /**
518 * Invoked when user selects the zoom size in the menu
519 */
520 void WebFrame::OnSetZoom(wxCommandEvent& evt)
521 {
522 if (evt.GetId() == m_tools_tiny->GetId())
523 {
524 m_browser->SetZoom(wxWEB_VIEW_ZOOM_TINY);
525 }
526 else if (evt.GetId() == m_tools_small->GetId())
527 {
528 m_browser->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
529 }
530 else if (evt.GetId() == m_tools_medium->GetId())
531 {
532 m_browser->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
533 }
534 else if (evt.GetId() == m_tools_large->GetId())
535 {
536 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
537 }
538 else if (evt.GetId() == m_tools_largest->GetId())
539 {
540 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
541 }
542 else
543 {
544 wxFAIL;
545 }
546 }
547
548 /**
549 * Callback invoked when a loading error occurs
550 */
551 void WebFrame::OnError(wxWebNavigationEvent& evt)
552 {
553 wxString errorCategory;
554 switch (evt.GetInt())
555 {
556 case wxWEB_NAV_ERR_CONNECTION:
557 errorCategory = "wxWEB_NAV_ERR_CONNECTION";
558 break;
559
560 case wxWEB_NAV_ERR_CERTIFICATE:
561 errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
562 break;
563
564 case wxWEB_NAV_ERR_AUTH:
565 errorCategory = "wxWEB_NAV_ERR_AUTH";
566 break;
567
568 case wxWEB_NAV_ERR_SECURITY:
569 errorCategory = "wxWEB_NAV_ERR_SECURITY";
570 break;
571
572 case wxWEB_NAV_ERR_NOT_FOUND:
573 errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
574 break;
575
576 case wxWEB_NAV_ERR_REQUEST:
577 errorCategory = "wxWEB_NAV_ERR_REQUEST";
578 break;
579
580 case wxWEB_NAV_ERR_USER_CANCELLED:
581 errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
582 break;
583
584 case wxWEB_NAV_ERR_OTHER:
585 errorCategory = "wxWEB_NAV_ERR_OTHER";
586 break;
587 }
588
589 wxLogMessage("Error; url='" + evt.GetHref() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
590
591 //Show the info bar with an error
592 m_info->ShowMessage(_("An error occurred loading ") + evt.GetHref() + "\n" +
593 "'" + errorCategory + "' (" + evt.GetString() + ")", wxICON_ERROR);
594
595 UpdateState();
596 }
597
598 /**
599 * Invoked when user selects "Print" from the menu
600 */
601 void WebFrame::OnPrint(wxCommandEvent& evt)
602 {
603 m_browser->Print();
604 }
605
606 SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
607 wxDialog(parent, wxID_ANY, "Source Code",
608 wxDefaultPosition, wxSize(700,500),
609 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
610 {
611 wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
612 text->SetMarginWidth(1, 30);
613 text->SetMarginType(1, wxSTC_MARGIN_NUMBER);
614 text->SetText(source);
615
616 text->StyleClearAll();
617 text->SetLexer(wxSTC_LEX_HTML);
618 text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255,0,0));
619 text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255,0,0));
620 text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255,0,0));
621 text->StyleSetForeground(wxSTC_H_TAG, wxColour(0,150,0));
622 text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0,150,0));
623 text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0,0,150));
624 text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0,0,150));
625 text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150,150,150));
626
627 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
628 sizer->Add(text, 1, wxEXPAND);
629 SetSizer(sizer);
630 }