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.

144 lines
4.6KB

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