Audio plugin host https://kx.studio/carla
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.

juce_Viewport.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. static bool viewportWouldScrollOnEvent (const Viewport* vp, const MouseInputSource& src) noexcept
  21. {
  22. if (vp != nullptr)
  23. {
  24. switch (vp->getScrollOnDragMode())
  25. {
  26. case Viewport::ScrollOnDragMode::all: return true;
  27. case Viewport::ScrollOnDragMode::nonHover: return ! src.canHover();
  28. case Viewport::ScrollOnDragMode::never: return false;
  29. }
  30. }
  31. return false;
  32. }
  33. using ViewportDragPosition = AnimatedPosition<AnimatedPositionBehaviours::ContinuousWithMomentum>;
  34. struct Viewport::DragToScrollListener : private MouseListener,
  35. private ViewportDragPosition::Listener
  36. {
  37. DragToScrollListener (Viewport& v) : viewport (v)
  38. {
  39. viewport.contentHolder.addMouseListener (this, true);
  40. offsetX.addListener (this);
  41. offsetY.addListener (this);
  42. offsetX.behaviour.setMinimumVelocity (60);
  43. offsetY.behaviour.setMinimumVelocity (60);
  44. }
  45. ~DragToScrollListener() override
  46. {
  47. viewport.contentHolder.removeMouseListener (this);
  48. Desktop::getInstance().removeGlobalMouseListener (this);
  49. }
  50. void stopOngoingAnimation()
  51. {
  52. offsetX.setPosition (offsetX.getPosition());
  53. offsetY.setPosition (offsetY.getPosition());
  54. }
  55. void positionChanged (ViewportDragPosition&, double) override
  56. {
  57. viewport.setViewPosition (originalViewPos - Point<int> ((int) offsetX.getPosition(),
  58. (int) offsetY.getPosition()));
  59. }
  60. void mouseDown (const MouseEvent& e) override
  61. {
  62. if (! isGlobalMouseListener && viewportWouldScrollOnEvent (&viewport, e.source))
  63. {
  64. offsetX.setPosition (offsetX.getPosition());
  65. offsetY.setPosition (offsetY.getPosition());
  66. // switch to a global mouse listener so we still receive mouseUp events
  67. // if the original event component is deleted
  68. viewport.contentHolder.removeMouseListener (this);
  69. Desktop::getInstance().addGlobalMouseListener (this);
  70. isGlobalMouseListener = true;
  71. scrollSource = e.source;
  72. }
  73. }
  74. void mouseDrag (const MouseEvent& e) override
  75. {
  76. if (e.source == scrollSource
  77. && ! doesMouseEventComponentBlockViewportDrag (e.eventComponent))
  78. {
  79. auto totalOffset = e.getEventRelativeTo (&viewport).getOffsetFromDragStart().toFloat();
  80. if (! isDragging && totalOffset.getDistanceFromOrigin() > 8.0f && viewportWouldScrollOnEvent (&viewport, e.source))
  81. {
  82. isDragging = true;
  83. originalViewPos = viewport.getViewPosition();
  84. offsetX.setPosition (0.0);
  85. offsetX.beginDrag();
  86. offsetY.setPosition (0.0);
  87. offsetY.beginDrag();
  88. }
  89. if (isDragging)
  90. {
  91. offsetX.drag (totalOffset.x);
  92. offsetY.drag (totalOffset.y);
  93. }
  94. }
  95. }
  96. void mouseUp (const MouseEvent& e) override
  97. {
  98. if (isGlobalMouseListener && e.source == scrollSource)
  99. endDragAndClearGlobalMouseListener();
  100. }
  101. void endDragAndClearGlobalMouseListener()
  102. {
  103. if (std::exchange (isDragging, false) == true)
  104. {
  105. offsetX.endDrag();
  106. offsetY.endDrag();
  107. }
  108. viewport.contentHolder.addMouseListener (this, true);
  109. Desktop::getInstance().removeGlobalMouseListener (this);
  110. isGlobalMouseListener = false;
  111. }
  112. bool doesMouseEventComponentBlockViewportDrag (const Component* eventComp)
  113. {
  114. for (auto c = eventComp; c != nullptr && c != &viewport; c = c->getParentComponent())
  115. if (c->getViewportIgnoreDragFlag())
  116. return true;
  117. return false;
  118. }
  119. Viewport& viewport;
  120. ViewportDragPosition offsetX, offsetY;
  121. Point<int> originalViewPos;
  122. MouseInputSource scrollSource = Desktop::getInstance().getMainMouseSource();
  123. bool isDragging = false;
  124. bool isGlobalMouseListener = false;
  125. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DragToScrollListener)
  126. };
  127. //==============================================================================
  128. Viewport::Viewport (const String& name)
  129. : Component (name),
  130. dragToScrollListener (std::make_unique<DragToScrollListener> (*this))
  131. {
  132. // content holder is used to clip the contents so they don't overlap the scrollbars
  133. addAndMakeVisible (contentHolder);
  134. contentHolder.setInterceptsMouseClicks (false, true);
  135. scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
  136. setInterceptsMouseClicks (false, true);
  137. setWantsKeyboardFocus (true);
  138. recreateScrollbars();
  139. }
  140. Viewport::~Viewport()
  141. {
  142. deleteOrRemoveContentComp();
  143. }
  144. //==============================================================================
  145. void Viewport::visibleAreaChanged (const Rectangle<int>&) {}
  146. void Viewport::viewedComponentChanged (Component*) {}
  147. //==============================================================================
  148. void Viewport::deleteOrRemoveContentComp()
  149. {
  150. if (contentComp != nullptr)
  151. {
  152. contentComp->removeComponentListener (this);
  153. if (deleteContent)
  154. {
  155. // This sets the content comp to a null pointer before deleting the old one, in case
  156. // anything tries to use the old one while it's in mid-deletion..
  157. std::unique_ptr<Component> oldCompDeleter (contentComp.get());
  158. contentComp = nullptr;
  159. }
  160. else
  161. {
  162. contentHolder.removeChildComponent (contentComp);
  163. contentComp = nullptr;
  164. }
  165. }
  166. }
  167. void Viewport::setViewedComponent (Component* const newViewedComponent, const bool deleteComponentWhenNoLongerNeeded)
  168. {
  169. if (contentComp.get() != newViewedComponent)
  170. {
  171. deleteOrRemoveContentComp();
  172. contentComp = newViewedComponent;
  173. deleteContent = deleteComponentWhenNoLongerNeeded;
  174. if (contentComp != nullptr)
  175. {
  176. contentHolder.addAndMakeVisible (contentComp);
  177. setViewPosition (Point<int>());
  178. contentComp->addComponentListener (this);
  179. }
  180. viewedComponentChanged (contentComp);
  181. updateVisibleArea();
  182. }
  183. }
  184. void Viewport::recreateScrollbars()
  185. {
  186. verticalScrollBar.reset();
  187. horizontalScrollBar.reset();
  188. verticalScrollBar .reset (createScrollBarComponent (true));
  189. horizontalScrollBar.reset (createScrollBarComponent (false));
  190. addChildComponent (verticalScrollBar.get());
  191. addChildComponent (horizontalScrollBar.get());
  192. getVerticalScrollBar().addListener (this);
  193. getHorizontalScrollBar().addListener (this);
  194. getVerticalScrollBar().addMouseListener (this, true);
  195. getHorizontalScrollBar().addMouseListener (this, true);
  196. resized();
  197. }
  198. int Viewport::getMaximumVisibleWidth() const { return contentHolder.getWidth(); }
  199. int Viewport::getMaximumVisibleHeight() const { return contentHolder.getHeight(); }
  200. bool Viewport::canScrollVertically() const noexcept { return contentComp->getY() < 0 || contentComp->getBottom() > getHeight(); }
  201. bool Viewport::canScrollHorizontally() const noexcept { return contentComp->getX() < 0 || contentComp->getRight() > getWidth(); }
  202. Point<int> Viewport::viewportPosToCompPos (Point<int> pos) const
  203. {
  204. jassert (contentComp != nullptr);
  205. auto contentBounds = contentHolder.getLocalArea (contentComp.get(), contentComp->getLocalBounds());
  206. Point<int> p (jmax (jmin (0, contentHolder.getWidth() - contentBounds.getWidth()), jmin (0, -(pos.x))),
  207. jmax (jmin (0, contentHolder.getHeight() - contentBounds.getHeight()), jmin (0, -(pos.y))));
  208. return p.transformedBy (contentComp->getTransform().inverted());
  209. }
  210. void Viewport::setViewPosition (const int xPixelsOffset, const int yPixelsOffset)
  211. {
  212. setViewPosition ({ xPixelsOffset, yPixelsOffset });
  213. }
  214. void Viewport::setViewPosition (Point<int> newPosition)
  215. {
  216. if (contentComp != nullptr)
  217. contentComp->setTopLeftPosition (viewportPosToCompPos (newPosition));
  218. }
  219. void Viewport::setViewPositionProportionately (const double x, const double y)
  220. {
  221. if (contentComp != nullptr)
  222. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  223. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  224. }
  225. bool Viewport::autoScroll (const int mouseX, const int mouseY, const int activeBorderThickness, const int maximumSpeed)
  226. {
  227. if (contentComp != nullptr)
  228. {
  229. int dx = 0, dy = 0;
  230. if (getHorizontalScrollBar().isVisible() || canScrollHorizontally())
  231. {
  232. if (mouseX < activeBorderThickness)
  233. dx = activeBorderThickness - mouseX;
  234. else if (mouseX >= contentHolder.getWidth() - activeBorderThickness)
  235. dx = (contentHolder.getWidth() - activeBorderThickness) - mouseX;
  236. if (dx < 0)
  237. dx = jmax (dx, -maximumSpeed, contentHolder.getWidth() - contentComp->getRight());
  238. else
  239. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  240. }
  241. if (getVerticalScrollBar().isVisible() || canScrollVertically())
  242. {
  243. if (mouseY < activeBorderThickness)
  244. dy = activeBorderThickness - mouseY;
  245. else if (mouseY >= contentHolder.getHeight() - activeBorderThickness)
  246. dy = (contentHolder.getHeight() - activeBorderThickness) - mouseY;
  247. if (dy < 0)
  248. dy = jmax (dy, -maximumSpeed, contentHolder.getHeight() - contentComp->getBottom());
  249. else
  250. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  251. }
  252. if (dx != 0 || dy != 0)
  253. {
  254. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  255. contentComp->getY() + dy);
  256. return true;
  257. }
  258. }
  259. return false;
  260. }
  261. void Viewport::componentMovedOrResized (Component&, bool, bool)
  262. {
  263. updateVisibleArea();
  264. }
  265. //==============================================================================
  266. void Viewport::setScrollOnDragMode (const ScrollOnDragMode mode)
  267. {
  268. scrollOnDragMode = mode;
  269. }
  270. bool Viewport::isCurrentlyScrollingOnDrag() const noexcept
  271. {
  272. return dragToScrollListener->isDragging;
  273. }
  274. //==============================================================================
  275. void Viewport::lookAndFeelChanged()
  276. {
  277. if (! customScrollBarThickness)
  278. {
  279. scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
  280. resized();
  281. }
  282. }
  283. void Viewport::resized()
  284. {
  285. updateVisibleArea();
  286. }
  287. //==============================================================================
  288. void Viewport::updateVisibleArea()
  289. {
  290. auto scrollbarWidth = getScrollBarThickness();
  291. const bool canShowAnyBars = getWidth() > scrollbarWidth && getHeight() > scrollbarWidth;
  292. const bool canShowHBar = showHScrollbar && canShowAnyBars;
  293. const bool canShowVBar = showVScrollbar && canShowAnyBars;
  294. bool hBarVisible = false, vBarVisible = false;
  295. Rectangle<int> contentArea;
  296. for (int i = 3; --i >= 0;)
  297. {
  298. hBarVisible = canShowHBar && ! getHorizontalScrollBar().autoHides();
  299. vBarVisible = canShowVBar && ! getVerticalScrollBar().autoHides();
  300. contentArea = getLocalBounds();
  301. if (contentComp != nullptr && ! contentArea.contains (contentComp->getBounds()))
  302. {
  303. hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth());
  304. vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight());
  305. if (vBarVisible)
  306. contentArea.setWidth (getWidth() - scrollbarWidth);
  307. if (hBarVisible)
  308. contentArea.setHeight (getHeight() - scrollbarWidth);
  309. if (! contentArea.contains (contentComp->getBounds()))
  310. {
  311. hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth());
  312. vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight());
  313. }
  314. }
  315. if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth);
  316. if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth);
  317. if (! vScrollbarRight && vBarVisible)
  318. contentArea.setX (scrollbarWidth);
  319. if (! hScrollbarBottom && hBarVisible)
  320. contentArea.setY (scrollbarWidth);
  321. if (contentComp == nullptr)
  322. {
  323. contentHolder.setBounds (contentArea);
  324. break;
  325. }
  326. auto oldContentBounds = contentComp->getBounds();
  327. contentHolder.setBounds (contentArea);
  328. // If the content has changed its size, that might affect our scrollbars, so go round again and re-calculate..
  329. if (oldContentBounds == contentComp->getBounds())
  330. break;
  331. }
  332. Rectangle<int> contentBounds;
  333. if (auto cc = contentComp.get())
  334. contentBounds = contentHolder.getLocalArea (cc, cc->getLocalBounds());
  335. auto visibleOrigin = -contentBounds.getPosition();
  336. auto& hbar = getHorizontalScrollBar();
  337. auto& vbar = getVerticalScrollBar();
  338. hbar.setBounds (contentArea.getX(), hScrollbarBottom ? contentArea.getHeight() : 0, contentArea.getWidth(), scrollbarWidth);
  339. hbar.setRangeLimits (0.0, contentBounds.getWidth());
  340. hbar.setCurrentRange (visibleOrigin.x, contentArea.getWidth());
  341. hbar.setSingleStepSize (singleStepX);
  342. if (canShowHBar && ! hBarVisible)
  343. visibleOrigin.setX (0);
  344. vbar.setBounds (vScrollbarRight ? contentArea.getWidth() : 0, contentArea.getY(), scrollbarWidth, contentArea.getHeight());
  345. vbar.setRangeLimits (0.0, contentBounds.getHeight());
  346. vbar.setCurrentRange (visibleOrigin.y, contentArea.getHeight());
  347. vbar.setSingleStepSize (singleStepY);
  348. if (canShowVBar && ! vBarVisible)
  349. visibleOrigin.setY (0);
  350. // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers.
  351. hbar.setVisible (hBarVisible);
  352. vbar.setVisible (vBarVisible);
  353. if (contentComp != nullptr)
  354. {
  355. auto newContentCompPos = viewportPosToCompPos (visibleOrigin);
  356. if (contentComp->getBounds().getPosition() != newContentCompPos)
  357. {
  358. contentComp->setTopLeftPosition (newContentCompPos); // (this will re-entrantly call updateVisibleArea again)
  359. return;
  360. }
  361. }
  362. const Rectangle<int> visibleArea (visibleOrigin.x, visibleOrigin.y,
  363. jmin (contentBounds.getWidth() - visibleOrigin.x, contentArea.getWidth()),
  364. jmin (contentBounds.getHeight() - visibleOrigin.y, contentArea.getHeight()));
  365. if (lastVisibleArea != visibleArea)
  366. {
  367. lastVisibleArea = visibleArea;
  368. visibleAreaChanged (visibleArea);
  369. }
  370. hbar.handleUpdateNowIfNeeded();
  371. vbar.handleUpdateNowIfNeeded();
  372. }
  373. //==============================================================================
  374. void Viewport::setSingleStepSizes (const int stepX, const int stepY)
  375. {
  376. if (singleStepX != stepX || singleStepY != stepY)
  377. {
  378. singleStepX = stepX;
  379. singleStepY = stepY;
  380. updateVisibleArea();
  381. }
  382. }
  383. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  384. const bool showHorizontalScrollbarIfNeeded,
  385. const bool allowVerticalScrollingWithoutScrollbar,
  386. const bool allowHorizontalScrollingWithoutScrollbar)
  387. {
  388. allowScrollingWithoutScrollbarV = allowVerticalScrollingWithoutScrollbar;
  389. allowScrollingWithoutScrollbarH = allowHorizontalScrollingWithoutScrollbar;
  390. if (showVScrollbar != showVerticalScrollbarIfNeeded
  391. || showHScrollbar != showHorizontalScrollbarIfNeeded)
  392. {
  393. showVScrollbar = showVerticalScrollbarIfNeeded;
  394. showHScrollbar = showHorizontalScrollbarIfNeeded;
  395. updateVisibleArea();
  396. }
  397. }
  398. void Viewport::setScrollBarThickness (const int thickness)
  399. {
  400. int newThickness;
  401. // To stay compatible with the previous code: use the
  402. // default thickness if thickness parameter is zero
  403. // or negative
  404. if (thickness <= 0)
  405. {
  406. customScrollBarThickness = false;
  407. newThickness = getLookAndFeel().getDefaultScrollbarWidth();
  408. }
  409. else
  410. {
  411. customScrollBarThickness = true;
  412. newThickness = thickness;
  413. }
  414. if (scrollBarThickness != newThickness)
  415. {
  416. scrollBarThickness = newThickness;
  417. updateVisibleArea();
  418. }
  419. }
  420. int Viewport::getScrollBarThickness() const
  421. {
  422. return scrollBarThickness;
  423. }
  424. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  425. {
  426. auto newRangeStartInt = roundToInt (newRangeStart);
  427. if (scrollBarThatHasMoved == horizontalScrollBar.get())
  428. {
  429. setViewPosition (newRangeStartInt, getViewPositionY());
  430. }
  431. else if (scrollBarThatHasMoved == verticalScrollBar.get())
  432. {
  433. setViewPosition (getViewPositionX(), newRangeStartInt);
  434. }
  435. }
  436. void Viewport::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
  437. {
  438. if (e.eventComponent == this)
  439. if (! useMouseWheelMoveIfNeeded (e, wheel))
  440. Component::mouseWheelMove (e, wheel);
  441. }
  442. void Viewport::mouseDown (const MouseEvent& e)
  443. {
  444. if (e.eventComponent == horizontalScrollBar.get() || e.eventComponent == verticalScrollBar.get())
  445. dragToScrollListener->stopOngoingAnimation();
  446. }
  447. static int rescaleMouseWheelDistance (float distance, int singleStepSize) noexcept
  448. {
  449. if (distance == 0.0f)
  450. return 0;
  451. distance *= 14.0f * (float) singleStepSize;
  452. return roundToInt (distance < 0 ? jmin (distance, -1.0f)
  453. : jmax (distance, 1.0f));
  454. }
  455. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel)
  456. {
  457. if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown()))
  458. {
  459. const bool canScrollVert = (allowScrollingWithoutScrollbarV || getVerticalScrollBar().isVisible());
  460. const bool canScrollHorz = (allowScrollingWithoutScrollbarH || getHorizontalScrollBar().isVisible());
  461. if (canScrollHorz || canScrollVert)
  462. {
  463. auto deltaX = rescaleMouseWheelDistance (wheel.deltaX, singleStepX);
  464. auto deltaY = rescaleMouseWheelDistance (wheel.deltaY, singleStepY);
  465. auto pos = getViewPosition();
  466. if (deltaX != 0 && deltaY != 0 && canScrollHorz && canScrollVert)
  467. {
  468. pos.x -= deltaX;
  469. pos.y -= deltaY;
  470. }
  471. else if (canScrollHorz && (deltaX != 0 || e.mods.isShiftDown() || ! canScrollVert))
  472. {
  473. pos.x -= deltaX != 0 ? deltaX : deltaY;
  474. }
  475. else if (canScrollVert && deltaY != 0)
  476. {
  477. pos.y -= deltaY;
  478. }
  479. if (pos != getViewPosition())
  480. {
  481. setViewPosition (pos);
  482. return true;
  483. }
  484. }
  485. }
  486. return false;
  487. }
  488. static bool isUpDownKeyPress (const KeyPress& key)
  489. {
  490. return key == KeyPress::upKey
  491. || key == KeyPress::downKey
  492. || key == KeyPress::pageUpKey
  493. || key == KeyPress::pageDownKey
  494. || key == KeyPress::homeKey
  495. || key == KeyPress::endKey;
  496. }
  497. static bool isLeftRightKeyPress (const KeyPress& key)
  498. {
  499. return key == KeyPress::leftKey
  500. || key == KeyPress::rightKey;
  501. }
  502. bool Viewport::keyPressed (const KeyPress& key)
  503. {
  504. const bool isUpDownKey = isUpDownKeyPress (key);
  505. if (getVerticalScrollBar().isVisible() && isUpDownKey)
  506. return getVerticalScrollBar().keyPressed (key);
  507. const bool isLeftRightKey = isLeftRightKeyPress (key);
  508. if (getHorizontalScrollBar().isVisible() && (isUpDownKey || isLeftRightKey))
  509. return getHorizontalScrollBar().keyPressed (key);
  510. return false;
  511. }
  512. bool Viewport::respondsToKey (const KeyPress& key)
  513. {
  514. return isUpDownKeyPress (key) || isLeftRightKeyPress (key);
  515. }
  516. ScrollBar* Viewport::createScrollBarComponent (bool isVertical)
  517. {
  518. return new ScrollBar (isVertical);
  519. }
  520. void Viewport::setScrollBarPosition (bool verticalScrollbarOnRight,
  521. bool horizontalScrollbarAtBottom)
  522. {
  523. vScrollbarRight = verticalScrollbarOnRight;
  524. hScrollbarBottom = horizontalScrollbarAtBottom;
  525. resized();
  526. }
  527. } // namespace juce