The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../jucedemo_headers.h"
  19. #if JUCE_WEB_BROWSER
  20. //==============================================================================
  21. /** We'll use a subclass of WebBrowserComponent to demonstrate how to get callbacks
  22. when the browser changes URL. You don't need to do this, you can just also
  23. just use the WebBrowserComponent class directly.
  24. */
  25. class DemoBrowserComponent : public WebBrowserComponent
  26. {
  27. public:
  28. //==============================================================================
  29. DemoBrowserComponent (TextEditor* addressTextBox_)
  30. : addressTextBox (addressTextBox_)
  31. {
  32. }
  33. // This method gets called when the browser is about to go to a new URL..
  34. bool pageAboutToLoad (const String& newURL)
  35. {
  36. // We'll just update our address box to reflect the new location..
  37. addressTextBox->setText (newURL, false);
  38. // we could return false here to tell the browser not to go ahead with
  39. // loading the page.
  40. return true;
  41. }
  42. //==============================================================================
  43. juce_UseDebuggingNewOperator
  44. private:
  45. TextEditor* addressTextBox;
  46. DemoBrowserComponent (DemoBrowserComponent&);
  47. DemoBrowserComponent& operator= (const DemoBrowserComponent&);
  48. };
  49. //==============================================================================
  50. class WebBrowserDemo : public Component,
  51. public TextEditor::Listener,
  52. public Button::Listener
  53. {
  54. public:
  55. //==============================================================================
  56. WebBrowserDemo()
  57. {
  58. setName ("Web Browser");
  59. // Create an address box..
  60. addAndMakeVisible (addressTextBox = new TextEditor());
  61. addressTextBox->setTextToShowWhenEmpty ("Enter a web address, e.g. http://www.rawmaterialsoftware.com", Colours::grey);
  62. addressTextBox->addListener (this);
  63. // create the actual browser component
  64. addAndMakeVisible (webView = new DemoBrowserComponent (addressTextBox));
  65. // add some buttons..
  66. addAndMakeVisible (goButton = new TextButton ("Go", "Go to URL"));
  67. goButton->addButtonListener (this);
  68. addAndMakeVisible (backButton = new TextButton ("<<", "Back"));
  69. backButton->addButtonListener (this);
  70. addAndMakeVisible (forwardButton = new TextButton (">>", "Forward"));
  71. forwardButton->addButtonListener (this);
  72. // send the browser to a start page..
  73. webView->goToURL ("http://www.google.com");
  74. }
  75. ~WebBrowserDemo()
  76. {
  77. deleteAllChildren();
  78. }
  79. void resized()
  80. {
  81. webView->setBounds (10, 45, getWidth() - 20, getHeight() - 55);
  82. goButton->setBounds (getWidth() - 45, 10, 35, 25);
  83. addressTextBox->setBounds (100, 10, getWidth() - 155, 25);
  84. backButton->setBounds (10, 10, 35, 25);
  85. forwardButton->setBounds (55, 10, 35, 25);
  86. }
  87. void textEditorTextChanged (TextEditor&) {}
  88. void textEditorEscapeKeyPressed (TextEditor&) {}
  89. void textEditorFocusLost (TextEditor&) {}
  90. void textEditorReturnKeyPressed (TextEditor&)
  91. {
  92. webView->goToURL (addressTextBox->getText());
  93. }
  94. void buttonClicked (Button* b)
  95. {
  96. if (b == backButton)
  97. webView->goBack();
  98. else if (b == forwardButton)
  99. webView->goForward();
  100. else if (b == goButton)
  101. webView->goToURL (addressTextBox->getText());
  102. }
  103. juce_UseDebuggingNewOperator
  104. private:
  105. DemoBrowserComponent* webView;
  106. TextEditor* addressTextBox;
  107. TextButton* goButton;
  108. TextButton* backButton;
  109. TextButton* forwardButton;
  110. };
  111. //==============================================================================
  112. Component* createWebBrowserDemo()
  113. {
  114. return new WebBrowserDemo();
  115. }
  116. #endif