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.

2131 lines
94KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #ifndef __JUCE_COMPONENT_JUCEHEADER__
  24. #define __JUCE_COMPONENT_JUCEHEADER__
  25. #include "mouse/juce_MouseCursor.h"
  26. #include "mouse/juce_MouseListener.h"
  27. #include "juce_ComponentListener.h"
  28. #include "keyboard/juce_KeyListener.h"
  29. #include "keyboard/juce_KeyboardFocusTraverser.h"
  30. #include "../graphics/effects/juce_ImageEffectFilter.h"
  31. #include "../graphics/geometry/juce_RectangleList.h"
  32. #include "../graphics/geometry/juce_BorderSize.h"
  33. #include "windows/juce_ComponentPeer.h"
  34. #include "../../events/juce_MessageListener.h"
  35. #include "../../../juce_core/text/juce_StringArray.h"
  36. #include "../../../juce_core/containers/juce_VoidArray.h"
  37. #include "../../../juce_core/containers/juce_PropertySet.h"
  38. class LookAndFeel;
  39. //==============================================================================
  40. /**
  41. The base class for all JUCE user-interface objects.
  42. */
  43. class JUCE_API Component : public MouseListener,
  44. protected MessageListener
  45. {
  46. public:
  47. //==============================================================================
  48. /** Creates a component.
  49. To get it to actually appear, you'll also need to:
  50. - Either add it to a parent component or use the addToDesktop() method to
  51. make it a desktop window
  52. - Set its size and position to something sensible
  53. - Use setVisible() to make it visible
  54. And for it to serve any useful purpose, you'll need to write a
  55. subclass of Component or use one of the other types of component from
  56. the library.
  57. */
  58. Component() throw();
  59. /** Destructor.
  60. Note that when a component is deleted, any child components it might
  61. contain are NOT deleted unless you explicitly call deleteAllChildren() first.
  62. */
  63. virtual ~Component();
  64. //==============================================================================
  65. /** Creates a component, setting its name at the same time.
  66. @see getName, setName
  67. */
  68. Component (const String& componentName) throw();
  69. /** Returns the name of this component.
  70. @see setName
  71. */
  72. const String& getName() const throw() { return componentName_; }
  73. /** Sets the name of this component.
  74. When the name changes, all registered ComponentListeners will receive a
  75. ComponentListener::componentNameChanged() callback.
  76. @see getName
  77. */
  78. virtual void setName (const String& newName);
  79. //==============================================================================
  80. /** Checks whether this Component object has been deleted.
  81. This will check whether this object is still a valid component, or whether
  82. it's been deleted.
  83. It's safe to call this on null or dangling pointers, but note that there is a
  84. small risk if another new (but different) component has been created at the
  85. same memory address which this one occupied, this methods can return a
  86. false positive.
  87. */
  88. bool isValidComponent() const throw();
  89. //==============================================================================
  90. /** Makes the component visible or invisible.
  91. This method will show or hide the component.
  92. Note that components default to being non-visible when first created.
  93. Also note that visible components won't be seen unless all their parent components
  94. are also visible.
  95. This method will call visibilityChanged() and also componentVisibilityChanged()
  96. for any component listeners that are interested in this component.
  97. @param shouldBeVisible whether to show or hide the component
  98. @see isVisible, isShowing, visibilityChanged, ComponentListener::componentVisibilityChanged
  99. */
  100. virtual void setVisible (bool shouldBeVisible);
  101. /** Tests whether the component is visible or not.
  102. this doesn't necessarily tell you whether this comp is actually on the screen
  103. because this depends on whether all the parent components are also visible - use
  104. isShowing() to find this out.
  105. @see isShowing, setVisible
  106. */
  107. bool isVisible() const throw() { return flags.visibleFlag; }
  108. /** Called when this component's visiblility changes.
  109. @see setVisible, isVisible
  110. */
  111. virtual void visibilityChanged();
  112. /** Tests whether this component and all its parents are visible.
  113. @returns true only if this component and all its parents are visible.
  114. @see isVisible
  115. */
  116. bool isShowing() const throw();
  117. /** Makes a component invisible using a groovy fade-out and animated zoom effect.
  118. To do this, this function will cunningly:
  119. - take a snapshot of the component as it currently looks
  120. - call setVisible(false) on the component
  121. - replace it with a special component that will continue drawing the
  122. snapshot, animating it and gradually making it more transparent
  123. - when it's gone, the special component will also be deleted
  124. As soon as this method returns, the component can be safely removed and deleted
  125. leaving the proxy to do the fade-out, so it's even ok to call this in a
  126. component's destructor.
  127. Passing non-zero x and y values will cause the ghostly component image to
  128. also whizz off by this distance while fading out. If the scale factor is
  129. not 1.0, it will also zoom from the component's current size to this new size.
  130. One thing to be careful about is that the parent component must be able to cope
  131. with this unknown component type being added to it.
  132. */
  133. void fadeOutComponent (const int lengthOfFadeOutInMilliseconds,
  134. const int deltaXToMove = 0,
  135. const int deltaYToMove = 0,
  136. const float scaleFactorAtEnd = 1.0f);
  137. //==============================================================================
  138. /** Makes this component appear as a window on the desktop.
  139. Note that before calling this, you should make sure that the component's opacity is
  140. set correctly using setOpaque(). If the component is non-opaque, the windowing
  141. system will try to create a special transparent window for it, which will generally take
  142. a lot more CPU to operate (and might not even be possible on some platforms).
  143. If the component is inside a parent component at the time this method is called, it
  144. will be first be removed from that parent. Likewise if a component on the desktop
  145. is subsequently added to another component, it'll be removed from the desktop.
  146. @param windowStyleFlags a combination of the flags specified in the
  147. ComponentPeer::StyleFlags enum, which define the
  148. window's characteristics.
  149. @param nativeWindowToAttachTo this allows an OS object to be passed-in as the window
  150. in which the juce component should place itself. On Windows,
  151. this would be a HWND, a HIViewRef on the Mac. Not necessarily
  152. supported on all platforms, and best left as 0 unless you know
  153. what you're doing
  154. @see removeFromDesktop, isOnDesktop, userTriedToCloseWindow,
  155. getPeer, ComponentPeer::setMinimised, ComponentPeer::StyleFlags,
  156. ComponentPeer::getStyleFlags, ComponentPeer::setFullScreen
  157. */
  158. virtual void addToDesktop (int windowStyleFlags,
  159. void* nativeWindowToAttachTo = 0);
  160. /** If the component is currently showing on the desktop, this will hide it.
  161. You can also use setVisible() to hide a desktop window temporarily, but
  162. removeFromDesktop() will free any system resources that are being used up.
  163. @see addToDesktop, isOnDesktop
  164. */
  165. void removeFromDesktop();
  166. /** Returns true if this component is currently showing on the desktop.
  167. @see addToDesktop, removeFromDesktop
  168. */
  169. bool isOnDesktop() const throw();
  170. /** Returns the heavyweight window that contains this component.
  171. If this component is itself on the desktop, this will return the window
  172. object that it is using. Otherwise, it will return the window of
  173. its top-level parent component.
  174. This may return 0 if there isn't a desktop component.
  175. @see addToDesktop, isOnDesktop
  176. */
  177. ComponentPeer* getPeer() const throw();
  178. /** For components on the desktop, this is called if the system wants to close the window.
  179. This is a signal that either the user or the system wants the window to close. The
  180. default implementation of this method will trigger an assertion to warn you that your
  181. component should do something about it, but you can override this to ignore the event
  182. if you want.
  183. */
  184. virtual void userTriedToCloseWindow();
  185. /** Called for a desktop component which has just been minimised or un-minimised.
  186. This will only be called for components on the desktop.
  187. @see getPeer, ComponentPeer::setMinimised, ComponentPeer::isMinimised
  188. */
  189. virtual void minimisationStateChanged (bool isNowMinimised);
  190. //==============================================================================
  191. /** Brings the component to the front of its siblings.
  192. If some of the component's siblings have had their 'always-on-top' flag set,
  193. then they will still be kept in front of this one (unless of course this
  194. one is also 'always-on-top').
  195. @param shouldAlsoGainFocus if true, this will also try to assign keyboard focus
  196. to the component (see grabKeyboardFocus() for more details)
  197. @see toBack, toBehind, setAlwaysOnTop
  198. */
  199. void toFront (const bool shouldAlsoGainFocus);
  200. /** Changes this component's z-order to be at the back of all its siblings.
  201. If the component is set to be 'always-on-top', it will only be moved to the
  202. back of the other other 'always-on-top' components.
  203. @see toFront, toBehind, setAlwaysOnTop
  204. */
  205. void toBack();
  206. /** Changes this component's z-order so that it's just behind another component.
  207. @see toFront, toBack
  208. */
  209. void toBehind (Component* const other);
  210. /** Sets whether the component should always be kept at the front of its siblings.
  211. @see isAlwaysOnTop
  212. */
  213. void setAlwaysOnTop (const bool shouldStayOnTop);
  214. /** Returns true if this component is set to always stay in front of its siblings.
  215. @see setAlwaysOnTop
  216. */
  217. bool isAlwaysOnTop() const throw();
  218. //==============================================================================
  219. /** Returns the x co-ordinate of the component's left edge.
  220. This is a distance in pixels from the left edge of the component's parent.
  221. @see getScreenX
  222. */
  223. inline int getX() const throw() { return bounds_.getX(); }
  224. /** Returns the y co-ordinate of the top of this component.
  225. This is a distance in pixels from the top edge of the component's parent.
  226. @see getScreenY
  227. */
  228. inline int getY() const throw() { return bounds_.getY(); }
  229. /** Returns the component's width in pixels. */
  230. inline int getWidth() const throw() { return bounds_.getWidth(); }
  231. /** Returns the component's height in pixels. */
  232. inline int getHeight() const throw() { return bounds_.getHeight(); }
  233. /** Returns the x co-ordinate of the component's right-hand edge.
  234. This is a distance in pixels from the left edge of the component's parent.
  235. */
  236. int getRight() const throw() { return bounds_.getRight(); }
  237. /** Returns the y co-ordinate of the bottom edge of this component.
  238. This is a distance in pixels from the top edge of the component's parent.
  239. */
  240. int getBottom() const throw() { return bounds_.getBottom(); }
  241. /** Returns this component's bounding box.
  242. The rectangle returned is relative to the top-left of the component's parent.
  243. */
  244. const Rectangle& getBounds() const throw() { return bounds_; }
  245. /** Returns the region of this component that's not obscured by other, opaque components.
  246. The RectangleList that is returned represents the area of this component
  247. which isn't covered by opaque child components.
  248. If includeSiblings is true, it will also take into account any siblings
  249. that may be overlapping the component.
  250. */
  251. void getVisibleArea (RectangleList& result,
  252. const bool includeSiblings) const;
  253. //==============================================================================
  254. /** Returns this component's x co-ordinate relative the the screen's top-left origin.
  255. @see getX, relativePositionToGlobal
  256. */
  257. int getScreenX() const throw();
  258. /** Returns this component's y co-ordinate relative the the screen's top-left origin.
  259. @see getY, relativePositionToGlobal
  260. */
  261. int getScreenY() const throw();
  262. /** Converts a position relative to this component's top-left into a screen co-ordinate.
  263. @see globalPositionToRelative, relativePositionToOtherComponent
  264. */
  265. void relativePositionToGlobal (int& x, int& y) const throw();
  266. /** Converts a screen co-ordinate into a position relative to this component's top-left.
  267. @see relativePositionToGlobal, relativePositionToOtherComponent
  268. */
  269. void globalPositionToRelative (int& x, int& y) const throw();
  270. /** Converts a position relative to this component's top-left into a position
  271. relative to another component's top-left.
  272. @see relativePositionToGlobal, globalPositionToRelative
  273. */
  274. void relativePositionToOtherComponent (const Component* const targetComponent,
  275. int& x, int& y) const throw();
  276. //==============================================================================
  277. /** Moves the component to a new position.
  278. Changes the component's top-left position (without changing its size).
  279. The position is relative to the top-left of the component's parent.
  280. If the component actually moves, this method will make a synchronous call to moved().
  281. @see setBounds, ComponentListener::componentMovedOrResized
  282. */
  283. void setTopLeftPosition (const int x, const int y);
  284. /** Moves the component to a new position.
  285. Changes the position of the component's top-right corner (keeping it the same size).
  286. The position is relative to the top-left of the component's parent.
  287. If the component actually moves, this method will make a synchronous call to moved().
  288. */
  289. void setTopRightPosition (const int x, const int y);
  290. /** Changes the size of the component.
  291. A synchronous call to resized() will be occur if the size actually changes.
  292. */
  293. void setSize (const int newWidth, const int newHeight);
  294. /** Changes the component's position and size.
  295. The co-ordinates are relative to the top-left of the component's parent, or relative
  296. to the origin of the screen is the component is on the desktop.
  297. If this method changes the component's top-left position, it will make a synchronous
  298. call to moved(). If it changes the size, it will also make a call to resized().
  299. @see setTopLeftPosition, setSize, ComponentListener::componentMovedOrResized
  300. */
  301. void setBounds (int x, int y, int width, int height);
  302. /** Changes the component's position and size.
  303. @see setBounds
  304. */
  305. void setBounds (const Rectangle& newBounds);
  306. /** Changes the component's position and size in terms of fractions of its parent's size.
  307. The values are factors of the parent's size, so for example
  308. setBoundsRelative (0.2f, 0.2f, 0.5f, 0.5f) would give it half the
  309. width and height of the parent, with its top-left position 20% of
  310. the way across and down the parent.
  311. */
  312. void setBoundsRelative (const float proportionalX, const float proportionalY,
  313. const float proportionalWidth, const float proportionalHeight);
  314. /** Changes the component's position and size based on the amount of space to leave around it.
  315. This will position the component within its parent, leaving the specified number of
  316. pixels around each edge.
  317. */
  318. void setBoundsInset (const BorderSize& borders);
  319. /** Positions the component within a given rectangle, keeping its proportions
  320. unchanged.
  321. If onlyReduceInSize is false, the component will be resized to fill as much of the
  322. rectangle as possible without changing its aspect ratio (the component's
  323. current size is used to determine its aspect ratio, so a zero-size component
  324. won't work here). If onlyReduceInSize is true, it will only be resized if it's
  325. too big to fit inside the rectangle.
  326. It will then be positioned within the rectangle according to the justification flags
  327. specified.
  328. */
  329. void setBoundsToFit (int x, int y, int width, int height,
  330. const Justification& justification,
  331. const bool onlyReduceInSize);
  332. /** Changes the position of the component's centre.
  333. Leaves the component's size unchanged, but sets the position of its centre
  334. relative to its parent's top-left.
  335. */
  336. void setCentrePosition (const int x, const int y);
  337. /** Changes the position of the component's centre.
  338. Leaves the position unchanged, but positions its centre relative to its
  339. parent's size. E.g. setCentreRelative (0.5f, 0.5f) would place it centrally in
  340. its parent.
  341. */
  342. void setCentreRelative (const float x, const float y);
  343. /** Changes the component's size and centres it within its parent.
  344. After changing the size, the component will be moved so that it's
  345. centred within its parent.
  346. */
  347. void centreWithSize (const int width, const int height);
  348. //==============================================================================
  349. /** Returns a proportion of the component's width.
  350. This is a handy equivalent of (getWidth() * proportion).
  351. */
  352. int proportionOfWidth (const float proportion) const throw();
  353. /** Returns a proportion of the component's height.
  354. This is a handy equivalent of (getHeight() * proportion).
  355. */
  356. int proportionOfHeight (const float proportion) const throw();
  357. /** Returns the width of the component's parent.
  358. If the component has no parent (i.e. if it's on the desktop), this will return
  359. the width of the screen.
  360. */
  361. int getParentWidth() const throw();
  362. /** Returns the height of the component's parent.
  363. If the component has no parent (i.e. if it's on the desktop), this will return
  364. the height of the screen.
  365. */
  366. int getParentHeight() const throw();
  367. /** Returns the screen co-ordinates of the monitor that contains this component.
  368. If there's only one monitor, this will return its size - if there are multiple
  369. monitors, it will return the area of the monitor that contains the component's
  370. centre.
  371. */
  372. const Rectangle getParentMonitorArea() const throw();
  373. //==============================================================================
  374. /** Returns the number of child components that this component contains.
  375. @see getChildComponent, getIndexOfChildComponent
  376. */
  377. int getNumChildComponents() const throw();
  378. /** Returns one of this component's child components, by it index.
  379. The component with index 0 is at the back of the z-order, the one at the
  380. front will have index (getNumChildComponents() - 1).
  381. If the index is out-of-range, this will return a null pointer.
  382. @see getNumChildComponents, getIndexOfChildComponent
  383. */
  384. Component* getChildComponent (const int index) const throw();
  385. /** Returns the index of this component in the list of child components.
  386. A value of 0 means it is first in the list (i.e. behind all other components). Higher
  387. values are further towards the front.
  388. Returns -1 if the component passed-in is not a child of this component.
  389. @see getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind
  390. */
  391. int getIndexOfChildComponent (const Component* const child) const throw();
  392. /** Adds a child component to this one.
  393. @param child the new component to add. If the component passed-in is already
  394. the child of another component, it'll first be removed from that.
  395. @param zOrder The index in the child-list at which this component should be inserted.
  396. A value of -1 will insert it in front of the others, 0 is the back.
  397. @see removeChildComponent, addAndMakeVisible, getChild,
  398. ComponentListener::componentChildrenChanged
  399. */
  400. void addChildComponent (Component* const child,
  401. int zOrder = -1);
  402. /** Adds a child component to this one, and also makes the child visible if it isn't.
  403. Quite a useful function, this is just the same as calling addChildComponent()
  404. followed by setVisible (true) on the child.
  405. */
  406. void addAndMakeVisible (Component* const child,
  407. int zOrder = -1);
  408. /** Removes one of this component's child-components.
  409. If the child passed-in isn't actually a child of this component (either because
  410. it's invalid or is the child of a different parent), then nothing is done.
  411. Note that removing a child will not delete it!
  412. @see addChildComponent, ComponentListener::componentChildrenChanged
  413. */
  414. void removeChildComponent (Component* const childToRemove);
  415. /** Removes one of this component's child-components by index.
  416. This will return a pointer to the component that was removed, or null if
  417. the index was out-of-range.
  418. Note that removing a child will not delete it!
  419. @see addChildComponent, ComponentListener::componentChildrenChanged
  420. */
  421. Component* removeChildComponent (const int childIndexToRemove);
  422. /** Removes all this component's children.
  423. Note that this won't delete them! To do that, use deleteAllChildren() instead.
  424. */
  425. void removeAllChildren();
  426. /** Removes all this component's children, and deletes them.
  427. @see removeAllChildren
  428. */
  429. void deleteAllChildren();
  430. /** Returns the component which this component is inside.
  431. If this is the highest-level component or hasn't yet been added to
  432. a parent, this will return null.
  433. */
  434. Component* getParentComponent() const throw() { return parentComponent_; }
  435. /** Searches the parent components for a component of a specified class.
  436. For example findParentComponentOfClass \<MyComp\>() would return the first parent
  437. component that can be dynamically cast to a MyComp, or will return 0 if none
  438. of the parents are suitable.
  439. N.B. The dummy parameter is needed to work around a VC6 compiler bug.
  440. */
  441. template <class TargetClass>
  442. TargetClass* findParentComponentOfClass (TargetClass* const dummyParameter = 0) const
  443. {
  444. (void) dummyParameter;
  445. Component* p = parentComponent_;
  446. while (p != 0)
  447. {
  448. TargetClass* target = dynamic_cast <TargetClass*> (p);
  449. if (target != 0)
  450. return target;
  451. p = p->parentComponent_;
  452. }
  453. return 0;
  454. }
  455. /** Returns the highest-level component which contains this one or its parents.
  456. This will search upwards in the parent-hierarchy from this component, until it
  457. finds the highest one that doesn't have a parent (i.e. is on the desktop or
  458. not yet added to a parent), and will return that.
  459. */
  460. Component* getTopLevelComponent() const throw();
  461. /** Checks whether a component is anywhere inside this component or its children.
  462. This will recursively check through this components children to see if the
  463. given component is anywhere inside.
  464. */
  465. bool isParentOf (const Component* possibleChild) const throw();
  466. //==============================================================================
  467. /** Called to indicate that the component's parents have changed.
  468. When a component is added or removed from its parent, this method will
  469. be called on all of its children (recursively - so all children of its
  470. children will also be called as well).
  471. Subclasses can override this if they need to react to this in some way.
  472. @see getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged
  473. */
  474. virtual void parentHierarchyChanged();
  475. /** Subclasses can use this callback to be told when children are added or removed.
  476. @see parentHierarchyChanged
  477. */
  478. virtual void childrenChanged();
  479. //==============================================================================
  480. /** Tests whether a given point inside the component.
  481. Overriding this method allows you to create components which only intercept
  482. mouse-clicks within a user-defined area.
  483. This is called to find out whether a particular x, y co-ordinate is
  484. considered to be inside the component or not, and is used by methods such
  485. as contains() and getComponentAt() to work out which component
  486. the mouse is clicked on.
  487. Components with custom shapes will probably want to override it to perform
  488. some more complex hit-testing.
  489. The default implementation of this method returns either true or false,
  490. depending on the value that was set by calling setInterceptsMouseClicks() (true
  491. is the default return value).
  492. Note that the hit-test region is not related to the opacity with which
  493. areas of a component are painted.
  494. Applications should never call hitTest() directly - instead use the
  495. contains() method, because this will also test for occlusion by the
  496. component's parent.
  497. Note that for components on the desktop, this method will be ignored, because it's
  498. not always possible to implement this behaviour on all platforms.
  499. @param x the x co-ordinate to test, relative to the left hand edge of this
  500. component. This value is guaranteed to be greater than or equal to
  501. zero, and less than the component's width
  502. @param y the y co-ordinate to test, relative to the top edge of this
  503. component. This value is guaranteed to be greater than or equal to
  504. zero, and less than the component's height
  505. @returns true if the click is considered to be inside the component
  506. @see setInterceptsMouseClicks, contains
  507. */
  508. virtual bool hitTest (int x, int y);
  509. /** Changes the default return value for the hitTest() method.
  510. Setting this to false is an easy way to make a component pass its mouse-clicks
  511. through to the components behind it.
  512. When a component is created, the default setting for this is true.
  513. @param allowClicksOnThisComponent if true, hitTest() will always return true; if false, it will
  514. return false (or true for child components if allowClicksOnChildComponents
  515. is true)
  516. @param allowClicksOnChildComponents if this is true and allowClicksOnThisComponent is false, then child
  517. components can be clicked on as normal but clicks on this component pass
  518. straight through; if this is false and allowClicksOnThisComponent
  519. is false, then neither this component nor any child components can
  520. be clicked on
  521. @see hitTest, getInterceptsMouseClicks
  522. */
  523. void setInterceptsMouseClicks (const bool allowClicksOnThisComponent,
  524. const bool allowClicksOnChildComponents) throw();
  525. /** Retrieves the current state of the mouse-click interception flags.
  526. On return, the two parameters are set to the state used in the last call to
  527. setInterceptsMouseClicks().
  528. @see setInterceptsMouseClicks
  529. */
  530. void getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  531. bool& allowsClicksOnChildComponents) const throw();
  532. /** Returns true if a given point lies within this component or one of its children.
  533. Never override this method! Use hitTest to create custom hit regions.
  534. @param x the x co-ordinate to test, relative to this component's left hand edge.
  535. @param y the y co-ordinate to test, relative to this component's top edge.
  536. @returns true if the point is within the component's hit-test area, but only if
  537. that part of the component isn't clipped by its parent component. Note
  538. that this won't take into account any overlapping sibling components
  539. which might be in the way - for that, see reallyContains()
  540. @see hitTest, reallyContains, getComponentAt
  541. */
  542. virtual bool contains (int x, int y);
  543. /** Returns true if a given point lies in this component, taking any overlapping
  544. siblings into account.
  545. @param x the x co-ordinate to test, relative to this component's left hand edge.
  546. @param y the y co-ordinate to test, relative to this component's top edge.
  547. @param returnTrueIfWithinAChild if the point actually lies within a child of this
  548. component, this determines the value that will
  549. be returned.
  550. @see contains, getComponentAt
  551. */
  552. bool reallyContains (int x, int y,
  553. const bool returnTrueIfWithinAChild);
  554. /** Returns the component at a certain point within this one.
  555. @param x the x co-ordinate to test, relative to this component's left hand edge.
  556. @param y the y co-ordinate to test, relative to this component's top edge.
  557. @returns the component that is at this position - which may be 0, this component,
  558. or one of its children. Note that overlapping siblings that might actually
  559. be in the way are not taken into account by this method - to account for these,
  560. instead call getComponentAt on the top-level parent of this component.
  561. @see hitTest, contains, reallyContains
  562. */
  563. Component* getComponentAt (const int x, const int y);
  564. //==============================================================================
  565. /** Marks the whole component as needing to be redrawn.
  566. Calling this will not do any repainting immediately, but will mark the component
  567. as 'dirty'. At some point in the near future the operating system will send a paint
  568. message, which will redraw all the dirty regions of all components.
  569. There's no guarantee about how soon after calling repaint() the redraw will actually
  570. happen, and other queued events may be delivered before a redraw is done.
  571. If the setBufferedToImage() method has been used to cause this component
  572. to use a buffer, the repaint() call will invalidate the component's buffer.
  573. To redraw just a subsection of the component rather than the whole thing,
  574. use the repaint (int, int, int, int) method.
  575. @see paint
  576. */
  577. void repaint() throw();
  578. /** Marks a subsection of this component as needing to be redrawn.
  579. Calling this will not do any repainting immediately, but will mark the given region
  580. of the component as 'dirty'. At some point in the near future the operating system
  581. will send a paint message, which will redraw all the dirty regions of all components.
  582. There's no guarantee about how soon after calling repaint() the redraw will actually
  583. happen, and other queued events may be delivered before a redraw is done.
  584. The region that is passed in will be clipped to keep it within the bounds of this
  585. component.
  586. @see repaint()
  587. */
  588. void repaint (const int x, const int y,
  589. const int width, const int height) throw();
  590. //==============================================================================
  591. /** Makes the component use an internal buffer to optimise its redrawing.
  592. Setting this flag to true will cause the component to allocate an
  593. internal buffer into which it paints itself, so that when asked to
  594. redraw itself, it can use this buffer rather than actually calling the
  595. paint() method.
  596. The buffer is kept until the repaint() method is called directly on
  597. this component (or until it is resized), when the image is invalidated
  598. and then redrawn the next time the component is painted.
  599. Note that only the drawing that happens within the component's paint()
  600. method is drawn into the buffer, it's child components are not buffered, and
  601. nor is the paintOverChildren() method.
  602. @see repaint, paint, createComponentSnapshot
  603. */
  604. void setBufferedToImage (const bool shouldBeBuffered) throw();
  605. /** Generates a snapshot of part of this component.
  606. This will return a new Image, the size of the rectangle specified,
  607. containing a snapshot of the specified area of the component and all
  608. its children.
  609. The image may or may not have an alpha-channel, depending on whether the
  610. image is opaque or not.
  611. If the clipImageToComponentBounds parameter is true and the area is greater than
  612. the size of the component, it'll be clipped. If clipImageToComponentBounds is false
  613. then parts of the component beyond its bounds can be drawn.
  614. The caller is responsible for deleting the image that is returned.
  615. @see paintEntireComponent
  616. */
  617. Image* createComponentSnapshot (const Rectangle& areaToGrab,
  618. const bool clipImageToComponentBounds = true);
  619. /** Draws this component and all its subcomponents onto the specified graphics
  620. context.
  621. You should very rarely have to use this method, it's simply there in case you need
  622. to draw a component with a custom graphics context for some reason, e.g. for
  623. creating a snapshot of the component.
  624. It calls paint(), paintOverChildren() and recursively calls paintEntireComponent()
  625. on its children in order to render the entire tree.
  626. The graphics context may be left in an undefined state after this method returns,
  627. so you may need to reset it if you're going to use it again.
  628. */
  629. void paintEntireComponent (Graphics& context);
  630. //==============================================================================
  631. /** Adds an effect filter to alter the component's appearance.
  632. When a component has an effect filter set, then this is applied to the
  633. results of its paint() method. There are a few preset effects, such as
  634. a drop-shadow or glow, but they can be user-defined as well.
  635. The effect that is passed in will not be deleted by the component - the
  636. caller must take care of deleting it.
  637. To remove an effect from a component, pass a null pointer in as the parameter.
  638. @see ImageEffectFilter, DropShadowEffect, GlowEffect
  639. */
  640. void setComponentEffect (ImageEffectFilter* const newEffect);
  641. /** Returns the current component effect.
  642. @see setComponentEffect
  643. */
  644. ImageEffectFilter* getComponentEffect() const throw() { return effect_; }
  645. //==============================================================================
  646. /** Finds the appropriate look-and-feel to use for this component.
  647. If the component hasn't had a look-and-feel explicitly set, this will
  648. return the parent's look-and-feel, or just the default one if there's no
  649. parent.
  650. @see setLookAndFeel, lookAndFeelChanged
  651. */
  652. LookAndFeel& getLookAndFeel() const throw();
  653. /** Sets the look and feel to use for this component.
  654. This will also change the look and feel for any child components that haven't
  655. had their look set explicitly.
  656. The object passed in will not be deleted by the component, so it's the caller's
  657. responsibility to manage it. It may be used at any time until this component
  658. has been deleted.
  659. Calling this method will also invoke the sendLookAndFeelChange() method.
  660. @see getLookAndFeel, lookAndFeelChanged
  661. */
  662. void setLookAndFeel (LookAndFeel* const newLookAndFeel);
  663. /** Called to let the component react to a change in the look-and-feel setting.
  664. When the look-and-feel is changed for a component, this will be called in
  665. all its child components, recursively.
  666. It can also be triggered manually by the sendLookAndFeelChange() method, in case
  667. an application uses a LookAndFeel class that might have changed internally.
  668. @see sendLookAndFeelChange, getLookAndFeel
  669. */
  670. virtual void lookAndFeelChanged();
  671. /** Calls the lookAndFeelChanged() method in this component and all its children.
  672. This will recurse through the children and their children, calling lookAndFeelChanged()
  673. on them all.
  674. @see lookAndFeelChanged
  675. */
  676. void sendLookAndFeelChange();
  677. //==============================================================================
  678. /** Indicates whether any parts of the component might be transparent.
  679. Components that always paint all of their contents with solid colour and
  680. thus completely cover any components behind them should use this method
  681. to tell the repaint system that they are opaque.
  682. This information is used to optimise drawing, because it means that
  683. objects underneath opaque windows don't need to be painted.
  684. By default, components are considered transparent, unless this is used to
  685. make it otherwise.
  686. @see isOpaque, getVisibleArea
  687. */
  688. void setOpaque (const bool shouldBeOpaque) throw();
  689. /** Returns true if no parts of this component are transparent.
  690. @returns the value that was set by setOpaque, (the default being false)
  691. @see setOpaque
  692. */
  693. bool isOpaque() const throw();
  694. //==============================================================================
  695. /** Indicates whether the component should be brought to the front when clicked.
  696. Setting this flag to true will cause the component to be brought to the front
  697. when the mouse is clicked somewhere inside it or its child components.
  698. Note that a top-level desktop window might still be brought to the front by the
  699. operating system when it's clicked, depending on how the OS works.
  700. By default this is set to false.
  701. @see setMouseClickGrabsKeyboardFocus
  702. */
  703. void setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw();
  704. /** Indicates whether the component should be brought to the front when clicked-on.
  705. @see setBroughtToFrontOnMouseClick
  706. */
  707. bool isBroughtToFrontOnMouseClick() const throw();
  708. //==============================================================================
  709. // Keyboard focus methods
  710. /** Sets a flag to indicate whether this component needs keyboard focus or not.
  711. By default components aren't actually interested in gaining the
  712. focus, but this method can be used to turn this on.
  713. See the grabKeyboardFocus() method for details about the way a component
  714. is chosen to receive the focus.
  715. @see grabKeyboardFocus, getWantsKeyboardFocus
  716. */
  717. void setWantsKeyboardFocus (const bool wantsFocus) throw();
  718. /** Returns true if the component is interested in getting keyboard focus.
  719. This returns the flag set by setWantsKeyboardFocus(). The default
  720. setting is false.
  721. @see setWantsKeyboardFocus
  722. */
  723. bool getWantsKeyboardFocus() const throw();
  724. //==============================================================================
  725. /** Chooses whether a click on this component automatically grabs the focus.
  726. By default this is set to true, but you might want a component which can
  727. be focused, but where you don't want the user to be able to affect it directly
  728. by clicking.
  729. */
  730. void setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus);
  731. /** Returns the last value set with setMouseClickGrabsKeyboardFocus().
  732. See setMouseClickGrabsKeyboardFocus() for more info.
  733. */
  734. bool getMouseClickGrabsKeyboardFocus() const throw();
  735. //==============================================================================
  736. /** Tries to give keyboard focus to this component.
  737. When the user clicks on a component or its grabKeyboardFocus()
  738. method is called, the following procedure is used to work out which
  739. component should get it:
  740. - if the component that was clicked on actually wants focus (as indicated
  741. by calling getWantsKeyboardFocus), it gets it.
  742. - if the component itself doesn't want focus, it will try to pass it
  743. on to whichever of its children is the default component, as determined by
  744. KeyboardFocusTraverser::getDefaultComponent()
  745. - if none of its children want focus at all, it will pass it up to its
  746. parent instead, unless it's a top-level component without a parent,
  747. in which case it just takes the focus itself.
  748. @see setWantsKeyboardFocus, getWantsKeyboardFocus, hasKeyboardFocus,
  749. getCurrentlyFocusedComponent, focusGained, focusLost,
  750. keyPressed, keyStateChanged
  751. */
  752. void grabKeyboardFocus();
  753. /** Returns true if this component currently has the keyboard focus.
  754. @param trueIfChildIsFocused if this is true, then the method returns true if
  755. either this component or any of its children (recursively)
  756. have the focus. If false, the method only returns true if
  757. this component has the focus.
  758. @see grabKeyboardFocus, setWantsKeyboardFocus, getCurrentlyFocusedComponent,
  759. focusGained, focusLost
  760. */
  761. bool hasKeyboardFocus (const bool trueIfChildIsFocused) const throw();
  762. /** Returns the component that currently has the keyboard focus.
  763. @returns the focused component, or null if nothing is focused.
  764. */
  765. static Component* getCurrentlyFocusedComponent() throw();
  766. //==============================================================================
  767. /** Tries to move the keyboard focus to one of this component's siblings.
  768. This will try to move focus to either the next or previous component. (This
  769. is the method that is used when shifting focus by pressing the tab key).
  770. Components for which getWantsKeyboardFocus() returns false are not looked at.
  771. @param moveToNext if true, the focus will move forwards; if false, it will
  772. move backwards
  773. @see grabKeyboardFocus, setFocusContainer, setWantsKeyboardFocus
  774. */
  775. void moveKeyboardFocusToSibling (const bool moveToNext);
  776. /** Creates a KeyboardFocusTraverser object to use to determine the logic by
  777. which focus should be passed from this component.
  778. The default implementation of this method will return a default
  779. KeyboardFocusTraverser if this component is a focus container (as determined
  780. by the setFocusContainer() method). If the component isn't a focus
  781. container, then it will recursively ask its parents for a KeyboardFocusTraverser.
  782. If you overrride this to return a custom KeyboardFocusTraverser, then
  783. this component and all its sub-components will use the new object to
  784. make their focusing decisions.
  785. The method should return a new object, which the caller is required to
  786. delete when no longer needed.
  787. */
  788. virtual KeyboardFocusTraverser* createFocusTraverser();
  789. /** Returns the focus order of this component, if one has been specified.
  790. By default components don't have a focus order - in that case, this
  791. will return 0. Lower numbers indicate that the component will be
  792. earlier in the focus traversal order.
  793. To change the order, call setExplicitFocusOrder().
  794. The focus order may be used by the KeyboardFocusTraverser class as part of
  795. its algorithm for deciding the order in which components should be traversed.
  796. See the KeyboardFocusTraverser class for more details on this.
  797. @see moveKeyboardFocusToSibling, createFocusTraverser, KeyboardFocusTraverser
  798. */
  799. int getExplicitFocusOrder() const throw();
  800. /** Sets the index used in determining the order in which focusable components
  801. should be traversed.
  802. A value of 0 or less is taken to mean that no explicit order is wanted, and
  803. that traversal should use other factors, like the component's position.
  804. @see getExplicitFocusOrder, moveKeyboardFocusToSibling
  805. */
  806. void setExplicitFocusOrder (const int newFocusOrderIndex) throw();
  807. /** Indicates whether this component is a parent for components that can have
  808. their focus traversed.
  809. This flag is used by the default implementation of the createFocusTraverser()
  810. method, which uses the flag to find the first parent component (of the currently
  811. focused one) which wants to be a focus container.
  812. So using this method to set the flag to 'true' causes this component to
  813. act as the top level within which focus is passed around.
  814. @see isFocusContainer, createFocusTraverser, moveKeyboardFocusToSibling
  815. */
  816. void setFocusContainer (const bool isFocusContainer) throw();
  817. /** Returns true if this component has been marked as a focus container.
  818. See setFocusContainer() for more details.
  819. @see setFocusContainer, moveKeyboardFocusToSibling, createFocusTraverser
  820. */
  821. bool isFocusContainer() const throw();
  822. //==============================================================================
  823. /** Returns true if the component (and all its parents) are enabled.
  824. Components are enabled by default, and can be disabled with setEnabled(). Exactly
  825. what difference this makes to the component depends on the type. E.g. buttons
  826. and sliders will choose to draw themselves differently, etc.
  827. Note that if one of this component's parents is disabled, this will always
  828. return false, even if this component itself is enabled.
  829. @see setEnabled, enablementChanged
  830. */
  831. bool isEnabled() const throw();
  832. /** Enables or disables this component.
  833. Disabling a component will also cause all of its child components to become
  834. disabled.
  835. Similarly, enabling a component which is inside a disabled parent
  836. component won't make any difference until the parent is re-enabled.
  837. @see isEnabled, enablementChanged
  838. */
  839. void setEnabled (const bool shouldBeEnabled);
  840. /** Callback to indicate that this component has been enabled or disabled.
  841. This can be triggered by one of the component's parent components
  842. being enabled or disabled, as well as changes to the component itself.
  843. The default implementation of this method does nothing; your class may
  844. wish to repaint itself or something when this happens.
  845. @see setEnabled, isEnabled
  846. */
  847. virtual void enablementChanged();
  848. //==============================================================================
  849. /** Changes the mouse cursor shape to use when the mouse is over this component.
  850. Note that the cursor set by this method can be overridden by the getMouseCursor
  851. method.
  852. @see MouseCursor
  853. */
  854. void setMouseCursor (const MouseCursor& cursorType) throw();
  855. /** Returns the mouse cursor shape to use when the mouse is over this component.
  856. The default implementation will return the cursor that was set by setCursor()
  857. but can be overridden for more specialised purposes, e.g. returning different
  858. cursors depending on the mouse position.
  859. @see MouseCursor
  860. */
  861. virtual const MouseCursor getMouseCursor();
  862. /** Forces the current mouse cursor to be updated.
  863. If you're overriding the getMouseCursor() method to control which cursor is
  864. displayed, then this will only be checked each time the user moves the mouse. So
  865. if you want to force the system to check that the cursor being displayed is
  866. up-to-date (even if the mouse is just sitting there), call this method.
  867. This isn't needed if you're only using setMouseCursor().
  868. */
  869. void updateMouseCursor() const throw();
  870. //==============================================================================
  871. /** Components can override this method to draw their content.
  872. The paint() method gets called when a region of a component needs redrawing,
  873. either because the component's repaint() method has been called, or because
  874. something has happened on the screen that means a section of a window needs
  875. to be redrawn.
  876. Any child components will draw themselves over whatever this method draws. If
  877. you need to paint over the top of your child components, you can also implement
  878. the paintOverChildren() method to do this.
  879. If you want to cause a component to redraw itself, this is done asynchronously -
  880. calling the repaint() method marks a region of the component as "dirty", and the
  881. paint() method will automatically be called sometime later, by the message thread,
  882. to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks),
  883. you never redraw something synchronously.
  884. You should never need to call this method directly - to take a snapshot of the
  885. component you could use createComponentSnapshot() or paintEntireComponent().
  886. @param g the graphics context that must be used to do the drawing operations.
  887. @see repaint, paintOverChildren, Graphics
  888. */
  889. virtual void paint (Graphics& g);
  890. /** Components can override this method to draw over the top of their children.
  891. For most drawing operations, it's better to use the normal paint() method,
  892. but if you need to overlay something on top of the children, this can be
  893. used.
  894. @see paint, Graphics
  895. */
  896. virtual void paintOverChildren (Graphics& g);
  897. //==============================================================================
  898. /** Called when the mouse moves inside this component.
  899. If the mouse button isn't pressed and the mouse moves over a component,
  900. this will be called to let the component react to this.
  901. A component will always get a mouseEnter callback before a mouseMove.
  902. @param e details about the position and status of the mouse event
  903. @see mouseEnter, mouseExit, mouseDrag, contains
  904. */
  905. virtual void mouseMove (const MouseEvent& e);
  906. /** Called when the mouse first enters this component.
  907. If the mouse button isn't pressed and the mouse moves into a component,
  908. this will be called to let the component react to this.
  909. When the mouse button is pressed and held down while being moved in
  910. or out of a component, no mouseEnter or mouseExit callbacks are made - only
  911. mouseDrag messages are sent to the component that the mouse was originally
  912. clicked on, until the button is released.
  913. If you're writing a component that needs to repaint itself when the mouse
  914. enters and exits, it might be quicker to use the setRepaintsOnMouseActivity()
  915. method.
  916. @param e details about the position and status of the mouse event
  917. @see mouseExit, mouseDrag, mouseMove, contains
  918. */
  919. virtual void mouseEnter (const MouseEvent& e);
  920. /** Called when the mouse moves out of this component.
  921. This will be called when the mouse moves off the edge of this
  922. component.
  923. If the mouse button was pressed, and it was then dragged off the
  924. edge of the component and released, then this callback will happen
  925. when the button is released, after the mouseUp callback.
  926. If you're writing a component that needs to repaint itself when the mouse
  927. enters and exits, it might be quicker to use the setRepaintsOnMouseActivity()
  928. method.
  929. @param e details about the position and status of the mouse event
  930. @see mouseEnter, mouseDrag, mouseMove, contains
  931. */
  932. virtual void mouseExit (const MouseEvent& e);
  933. /** Called when a mouse button is pressed while it's over this component.
  934. The MouseEvent object passed in contains lots of methods for finding out
  935. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  936. were held down at the time.
  937. Once a button is held down, the mouseDrag method will be called when the
  938. mouse moves, until the button is released.
  939. @param e details about the position and status of the mouse event
  940. @see mouseUp, mouseDrag, mouseDoubleClick, contains
  941. */
  942. virtual void mouseDown (const MouseEvent& e);
  943. /** Called when the mouse is moved while a button is held down.
  944. When a mouse button is pressed inside a component, that component
  945. receives mouseDrag callbacks each time the mouse moves, even if the
  946. mouse strays outside the component's bounds.
  947. If you want to be able to drag things off the edge of a component
  948. and have the component scroll when you get to the edges, the
  949. beginDragAutoRepeat() method might be useful.
  950. @param e details about the position and status of the mouse event
  951. @see mouseDown, mouseUp, mouseMove, contains, beginDragAutoRepeat
  952. */
  953. virtual void mouseDrag (const MouseEvent& e);
  954. /** Called when a mouse button is released.
  955. A mouseUp callback is sent to the component in which a button was pressed
  956. even if the mouse is actually over a different component when the
  957. button is released.
  958. The MouseEvent object passed in contains lots of methods for finding out
  959. which buttons were down just before they were released.
  960. @param e details about the position and status of the mouse event
  961. @see mouseDown, mouseDrag, mouseDoubleClick, contains
  962. */
  963. virtual void mouseUp (const MouseEvent& e);
  964. /** Called when a mouse button has been double-clicked in this component.
  965. The MouseEvent object passed in contains lots of methods for finding out
  966. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  967. were held down at the time.
  968. For altering the time limit used to detect double-clicks,
  969. see MouseEvent::setDoubleClickTimeout.
  970. @param e details about the position and status of the mouse event
  971. @see mouseDown, mouseUp, MouseEvent::setDoubleClickTimeout,
  972. MouseEvent::getDoubleClickTimeout
  973. */
  974. virtual void mouseDoubleClick (const MouseEvent& e);
  975. /** Called when the mouse-wheel is moved.
  976. This callback is sent to the component that the mouse is over when the
  977. wheel is moved.
  978. If not overridden, the component will forward this message to its parent, so
  979. that parent components can collect mouse-wheel messages that happen to
  980. child components which aren't interested in them.
  981. @param e details about the position and status of the mouse event
  982. @param wheelIncrementX the speed and direction of the horizontal scroll-wheel - a positive
  983. value means the wheel has been pushed to the right, negative means it
  984. was pushed to the left
  985. @param wheelIncrementY the speed and direction of the vertical scroll-wheel - a positive
  986. value means the wheel has been pushed upwards, negative means it
  987. was pushed downwards
  988. */
  989. virtual void mouseWheelMove (const MouseEvent& e,
  990. float wheelIncrementX,
  991. float wheelIncrementY);
  992. //==============================================================================
  993. /** Ensures that a non-stop stream of mouse-drag events will be sent during the
  994. next mouse-drag operation.
  995. This allows you to make sure that mouseDrag() events sent continuously, even
  996. when the mouse isn't moving. This can be useful for things like auto-scrolling
  997. components when the mouse is near an edge.
  998. Call this method during a mouseDown() or mouseDrag() callback, specifying the
  999. minimum interval between consecutive mouse drag callbacks. The callbacks
  1000. will continue until the mouse is released, and then the interval will be reset,
  1001. so you need to make sure it's called every time you begin a drag event. If it
  1002. is called when the mouse isn't actually being pressed, it will apply to the next
  1003. mouse-drag operation that happens.
  1004. Passing an interval of 0 or less will cancel the auto-repeat.
  1005. @see mouseDrag
  1006. */
  1007. static void beginDragAutoRepeat (const int millisecondIntervalBetweenCallbacks);
  1008. /** Causes automatic repaints when the mouse enters or exits this component.
  1009. If turned on, then when the mouse enters/exits, or when the button is pressed/released
  1010. on the component, it will trigger a repaint.
  1011. This is handy for things like buttons that need to draw themselves differently when
  1012. the mouse moves over them, and it avoids having to override all the different mouse
  1013. callbacks and call repaint().
  1014. @see mouseEnter, mouseExit, mouseDown, mouseUp
  1015. */
  1016. void setRepaintsOnMouseActivity (const bool shouldRepaint) throw();
  1017. /** Registers a listener to be told when mouse events occur in this component.
  1018. If you need to get informed about mouse events in a component but can't or
  1019. don't want to override its methods, you can attach any number of listeners
  1020. to the component, and these will get told about the events in addition to
  1021. the component's own callbacks being called.
  1022. Note that a MouseListener can also be attached to more than one component.
  1023. @param newListener the listener to register
  1024. @param wantsEventsForAllNestedChildComponents if true, the listener will receive callbacks
  1025. for events that happen to any child component
  1026. within this component, including deeply-nested
  1027. child components. If false, it will only be
  1028. told about events that this component handles.
  1029. @see MouseListener, removeMouseListener
  1030. */
  1031. void addMouseListener (MouseListener* const newListener,
  1032. const bool wantsEventsForAllNestedChildComponents) throw();
  1033. /** Deregisters a mouse listener.
  1034. @see addMouseListener, MouseListener
  1035. */
  1036. void removeMouseListener (MouseListener* const listenerToRemove) throw();
  1037. //==============================================================================
  1038. /** Adds a listener that wants to hear about keypresses that this component receives.
  1039. The listeners that are registered with a component are called by its keyPressed() or
  1040. keyStateChanged() methods (assuming these haven't been overridden to do something else).
  1041. If you add an object as a key listener, be careful to remove it when the object
  1042. is deleted, or the component will be left with a dangling pointer.
  1043. @see keyPressed, keyStateChanged, removeKeyListener
  1044. */
  1045. void addKeyListener (KeyListener* const newListener) throw();
  1046. /** Removes a previously-registered key listener.
  1047. @see addKeyListener
  1048. */
  1049. void removeKeyListener (KeyListener* const listenerToRemove) throw();
  1050. /** Called when a key is pressed.
  1051. When a key is pressed, the component that has the keyboard focus will have this
  1052. method called. Remember that a component will only be given the focus if its
  1053. setWantsKeyboardFocus() method has been used to enable this.
  1054. The default implementation of this method does the following:
  1055. - calls its parent's keyPressed() method, so that its parents will get a chance
  1056. to use any keypresses that this component isn't interested in.
  1057. - calls the keyPressed() methods of any KeyListeners that have registered with the
  1058. addKeyListener() method.
  1059. If you want to use the keypresses that reach this component and stop them being sent up to
  1060. the parents, override this method. Of course a component can consume some keypresses
  1061. selectively and then for others, just call the superclass's Component::keyPressed method
  1062. to pass on the unwanted ones.
  1063. @see keyStateChanged, getCurrentlyFocusedComponent, addKeyListener
  1064. */
  1065. virtual void keyPressed (const KeyPress& key);
  1066. /** Called when a key is pressed or released.
  1067. Whenever a key on the keyboard is pressed or released (including modifier keys
  1068. like shift and ctrl), this method will be called on the component that currently
  1069. has the keyboard focus. Remember that a component will only be given the focus if
  1070. its setWantsKeyboardFocus() method has been used to enable this.
  1071. To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown()
  1072. method.
  1073. The default implementation of this method does the following:
  1074. - calls its parent's keyStateChanged() method, so that its parents will get a chance
  1075. to use any events that this component isn't interested in.
  1076. - calls the keyStateChanged() methods of any KeyListeners that have registered with the
  1077. addKeyListener() method.
  1078. @see keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener
  1079. */
  1080. virtual void keyStateChanged();
  1081. /** Called when a modifier key is pressed or released.
  1082. Whenever the shift, control, alt or command keys are pressed or released,
  1083. this method will be called on the component that currently has the keyboard focus.
  1084. Remember that a component will only be given the focus if its setWantsKeyboardFocus()
  1085. method has been used to enable this.
  1086. The default implementation of this method actually calls its parent's modifierKeysChanged
  1087. method, so that focused components which aren't interested in this will give their
  1088. parents a chance to act on the event instead.
  1089. @see keyStateChanged, ModifierKeys
  1090. */
  1091. virtual void modifierKeysChanged (const ModifierKeys& modifiers);
  1092. //==============================================================================
  1093. /** Enumeration used by the focusChanged() and focusLost() methods. */
  1094. enum FocusChangeType
  1095. {
  1096. focusChangedByMouseClick, /**< Means that the user clicked the mouse to change focus. */
  1097. focusChangedByTabKey, /**< Means that the user pressed the tab key to move the focus. */
  1098. focusChangedDirectly /**< Means that the focus was changed by a call to grabKeyboardFocus(). */
  1099. };
  1100. /** Called to indicate that this component has just acquired the keyboard focus.
  1101. @see focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  1102. */
  1103. virtual void focusGained (FocusChangeType cause);
  1104. /** Called to indicate that this component has just lost the keyboard focus.
  1105. @see focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  1106. */
  1107. virtual void focusLost (FocusChangeType cause);
  1108. /** Called to indicate that one of this component's children has been focused or unfocused.
  1109. Essentially this means that the return value of a call to hasKeyboardFocus (true) has
  1110. changed. It happens when focus moves from one of this component's children (at any depth)
  1111. to a component that isn't contained in this one, (or vice-versa).
  1112. @see focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  1113. */
  1114. virtual void focusOfChildComponentChanged (FocusChangeType cause);
  1115. //==============================================================================
  1116. /** Returns true if the mouse is currently over this component.
  1117. If the mouse isn't over the component, this will return false, even if the
  1118. mouse is currently being dragged - so you can use this in your mouseDrag
  1119. method to find out whether it's really over the component or not.
  1120. Note that when the mouse button is being held down, then the only component
  1121. for which this method will return true is the one that was originally
  1122. clicked on.
  1123. @see isMouseButtonDown. isMouseOverOrDragging, mouseDrag
  1124. */
  1125. bool isMouseOver() const throw();
  1126. /** Returns true if the mouse button is currently held down in this component.
  1127. Note that this is a test to see whether the mouse is being pressed in this
  1128. component, so it'll return false if called on component A when the mouse
  1129. is actually being dragged in component B.
  1130. @see isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging
  1131. */
  1132. bool isMouseButtonDown() const throw();
  1133. /** True if the mouse is over this component, or if it's being dragged in this component.
  1134. This is a handy equivalent to (isMouseOver() || isMouseButtonDown()).
  1135. @see isMouseOver, isMouseButtonDown, isMouseButtonDownAnywhere
  1136. */
  1137. bool isMouseOverOrDragging() const throw();
  1138. /** Returns true if a mouse button is currently down.
  1139. Unlike isMouseButtonDown, this will test the current state of the
  1140. buttons without regard to which component (if any) it has been
  1141. pressed in.
  1142. @see isMouseButtonDown, ModifierKeys
  1143. */
  1144. static bool isMouseButtonDownAnywhere() throw();
  1145. /** Returns the mouse's current position, relative to this component.
  1146. The co-ordinates are relative to the component's top-left corner.
  1147. */
  1148. void getMouseXYRelative (int& x, int& y) const throw();
  1149. /** Returns the component that's currently underneath the mouse.
  1150. @returns the component or 0 if there isn't one.
  1151. @see contains, getComponentAt
  1152. */
  1153. static Component* getComponentUnderMouse() throw();
  1154. /** Allows the mouse to move beyond the edges of the screen.
  1155. Calling this method when the mouse button is currently pressed inside this component
  1156. will remove the cursor from the screen and allow the mouse to (seem to) move beyond
  1157. the edges of the screen.
  1158. This means that the co-ordinates returned to mouseDrag() will be unbounded, and this
  1159. can be used for things like custom slider controls or dragging objects around, where
  1160. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  1161. The unbounded mode is automatically turned off when the mouse button is released, or
  1162. it can be turned off explicitly by calling this method again.
  1163. @param shouldUnboundedMovementBeEnabled whether to turn this mode on or off
  1164. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  1165. hidden; if true, it will only be hidden when it
  1166. is moved beyond the edge of the screen
  1167. */
  1168. void enableUnboundedMouseMovement (bool shouldUnboundedMovementBeEnabled,
  1169. bool keepCursorVisibleUntilOffscreen = false) throw();
  1170. //==============================================================================
  1171. /** Called when this component's size has been changed.
  1172. A component can implement this method to do things such as laying out its
  1173. child components when its width or height changes.
  1174. The method is called synchronously as a result of the setBounds or setSize
  1175. methods, so repeatedly changing a components size will repeatedly call its
  1176. resized method (unlike things like repainting, where multiple calls to repaint
  1177. are coalesced together).
  1178. If the component is a top-level window on the desktop, its size could also
  1179. be changed by operating-system factors beyond the application's control.
  1180. @see moved, setSize
  1181. */
  1182. virtual void resized();
  1183. /** Called when this component's position has been changed.
  1184. This is called when the position relative to its parent changes, not when
  1185. its absolute position on the screen changes (so it won't be called for
  1186. all child components when a parent component is moved).
  1187. The method is called synchronously as a result of the setBounds, setTopLeftPosition
  1188. or any of the other repositioning methods, and like resized(), it will be
  1189. called each time those methods are called.
  1190. If the component is a top-level window on the desktop, its position could also
  1191. be changed by operating-system factors beyond the application's control.
  1192. @see resized, setBounds
  1193. */
  1194. virtual void moved();
  1195. /** Called when one of this component's children is moved or resized.
  1196. If the parent wants to know about changes to its immediate children (not
  1197. to children of its children), this is the method to override.
  1198. @see moved, resized, parentSizeChanged
  1199. */
  1200. virtual void childBoundsChanged (Component* child);
  1201. /** Called when this component's immediate parent has been resized.
  1202. If the component is a top-level window, this indicates that the screen size
  1203. has changed.
  1204. @see childBoundsChanged, moved, resized
  1205. */
  1206. virtual void parentSizeChanged();
  1207. /** Called when this component has been moved to the front of its siblings.
  1208. The component may have been brought to the front by the toFront() method, or
  1209. by the operating system if it's a top-level window.
  1210. @see toFront
  1211. */
  1212. virtual void broughtToFront();
  1213. /** Adds a listener to be told about changes to the component hierarchy or position.
  1214. Component listeners get called when this component's size, position or children
  1215. change - see the ComponentListener class for more details.
  1216. @param newListener the listener to register - if this is already registered, it
  1217. will be ignored.
  1218. @see ComponentListener, removeComponentListener
  1219. */
  1220. void addComponentListener (ComponentListener* const newListener) throw();
  1221. /** Removes a component listener.
  1222. @see addComponentListener
  1223. */
  1224. void removeComponentListener (ComponentListener* const listenerToRemove) throw();
  1225. //==============================================================================
  1226. /** Called when files are dragged-and-dropped onto this component.
  1227. If the component isn't interested in the files, it should return false, to indicate
  1228. that its parent can be offered the files instead.
  1229. @param filenames a list of the filenames of the files that were dropped
  1230. @param mouseX x co-ordinate of the mouse when they were dropped, (relative to this
  1231. component's top-left)
  1232. @param mouseY y co-ordinate of the mouse when they were dropped, (relative to this
  1233. component's top-left)
  1234. */
  1235. virtual bool filesDropped (const StringArray& filenames,
  1236. int mouseX,
  1237. int mouseY);
  1238. //==============================================================================
  1239. /** Dispatches a numbered message to this component.
  1240. This is a quick and cheap way of allowing simple asynchronous messages to
  1241. be sent to components. It's also safe, because if the component that you
  1242. send the message to is a null or dangling pointer, this won't cause an error.
  1243. The command ID is later delivered to the component's handleCommandMessage() method by
  1244. the application's message queue.
  1245. @see handleCommandMessage
  1246. */
  1247. void postCommandMessage (const int commandId) throw();
  1248. /** Called to handle a command that was sent by postCommandMessage().
  1249. This is called by the message thread when a command message arrives, and
  1250. the component can override this method to process it in any way it needs to.
  1251. @see postCommandMessage
  1252. */
  1253. virtual void handleCommandMessage (int commandId);
  1254. //==============================================================================
  1255. /** Runs a component modally, waiting until the loop terminates.
  1256. This method first makes the component visible, brings it to the front and
  1257. gives it the keyboard focus.
  1258. It then runs a loop, dispatching messages from the system message queue, but
  1259. blocking all mouse or keyboard messages from reaching any components other
  1260. than this one and its children.
  1261. This loop continues until the component's exitModalState() method is called (or
  1262. the component is deleted), and then this method returns, returning the value
  1263. passed into exitModalState().
  1264. @see enterModalState, exitModalState, isCurrentlyModal, getCurrentlyModalComponent,
  1265. isCurrentlyBlockedByAnotherModalComponent, MessageManager::dispatchNextMessage
  1266. */
  1267. int runModalLoop();
  1268. /** Puts the component into a modal state.
  1269. This makes the component modal, so that messages are blocked from reaching
  1270. any components other than this one and its children, but unlike runModalLoop(),
  1271. this method returns immediately.
  1272. If takeKeyboardFocus is true, the component will use grabKeyboardFocus() to
  1273. get the focus, which is usually what you'll want it to do. If not, it will leave
  1274. the focus unchanged.
  1275. @see exitModalState, runModalLoop
  1276. */
  1277. void enterModalState (const bool takeKeyboardFocus = true);
  1278. /** Ends a component's modal state.
  1279. If this component is currently modal, this will turn of its modalness, and return
  1280. a value to the runModalLoop() method that might have be running its modal loop.
  1281. @see runModalLoop, enterModalState, isCurrentlyModal
  1282. */
  1283. void exitModalState (const int returnValue);
  1284. /** Returns true if this component is the modal one.
  1285. It's possible to have nested modal components, e.g. a pop-up dialog box
  1286. that launches another pop-up, but this will only return true for
  1287. the one at the top of the stack.
  1288. @see getCurrentlyModalComponent
  1289. */
  1290. bool isCurrentlyModal() const throw();
  1291. /** Returns the component that is currently modal.
  1292. @returns the modal component, or null if no components are modal
  1293. @see runModalLoop, isCurrentlyModal
  1294. */
  1295. static Component* getCurrentlyModalComponent() throw();
  1296. /** Checks whether there's a modal component somewhere that's stopping this one
  1297. from receiving messages.
  1298. If there is a modal component, its canModalEventBeSentToComponent() method
  1299. will be called to see if it will still allow this component to receive events.
  1300. @see runModalLoop, getCurrentlyModalComponent
  1301. */
  1302. bool isCurrentlyBlockedByAnotherModalComponent() const throw();
  1303. /** When a component is modal, this callback allows it to choose which other
  1304. components can still receive events.
  1305. When a modal component is active and the user clicks on a non-modal component,
  1306. this method is called on the modal component, and if it returns true, the
  1307. event is allowed to reach its target. If it returns false, the event is blocked
  1308. and the inputAttemptWhenModal() callback is made.
  1309. It called by the isCurrentlyBlockedByAnotherModalComponent() method. The default
  1310. implementation just returns false in all cases.
  1311. */
  1312. virtual bool canModalEventBeSentToComponent (const Component* targetComponent);
  1313. /** Called when the user tries to click on a component that is blocked by another
  1314. modal component.
  1315. When a component is modal and the user clicks on one of the other components,
  1316. the modal component will receive this callback.
  1317. The default implementation of this method will play a beep, and bring the currently
  1318. modal component to the front, but it can be overridden to do other tasks.
  1319. @see isCurrentlyBlockedByAnotherModalComponent, canModalEventBeSentToComponent
  1320. */
  1321. virtual void inputAttemptWhenModal();
  1322. //==============================================================================
  1323. /** Returns one of the component's properties as a string.
  1324. @param keyName the name of the property to retrieve
  1325. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  1326. properties, then it will check whether the parent component has
  1327. the key.
  1328. @param defaultReturnValue a value to return if the named property doesn't actually exist
  1329. */
  1330. const String getComponentProperty (const String& keyName,
  1331. const bool useParentComponentIfNotFound,
  1332. const String& defaultReturnValue = String::empty) const throw();
  1333. /** Returns one of the properties as an integer.
  1334. @param keyName the name of the property to retrieve
  1335. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  1336. properties, then it will check whether the parent component has
  1337. the key.
  1338. @param defaultReturnValue a value to return if the named property doesn't actually exist
  1339. */
  1340. int getComponentPropertyInt (const String& keyName,
  1341. const bool useParentComponentIfNotFound,
  1342. const int defaultReturnValue = 0) const throw();
  1343. /** Returns one of the properties as an double.
  1344. @param keyName the name of the property to retrieve
  1345. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  1346. properties, then it will check whether the parent component has
  1347. the key.
  1348. @param defaultReturnValue a value to return if the named property doesn't actually exist
  1349. */
  1350. double getComponentPropertyDouble (const String& keyName,
  1351. const bool useParentComponentIfNotFound,
  1352. const double defaultReturnValue = 0.0) const throw();
  1353. /** Returns one of the properties as an boolean.
  1354. The result will be true if the string found for this key name can be parsed as a non-zero
  1355. integer.
  1356. @param keyName the name of the property to retrieve
  1357. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  1358. properties, then it will check whether the parent component has
  1359. the key.
  1360. @param defaultReturnValue a value to return if the named property doesn't actually exist
  1361. */
  1362. bool getComponentPropertyBool (const String& keyName,
  1363. const bool useParentComponentIfNotFound,
  1364. const bool defaultReturnValue = false) const throw();
  1365. /** Returns one of the properties as an colour.
  1366. @param keyName the name of the property to retrieve
  1367. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  1368. properties, then it will check whether the parent component has
  1369. the key.
  1370. @param defaultReturnValue a colour to return if the named property doesn't actually exist
  1371. */
  1372. const Colour getComponentPropertyColour (const String& keyName,
  1373. const bool useParentComponentIfNotFound,
  1374. const Colour& defaultReturnValue = Colours::black) const throw();
  1375. /** Sets a named property as a string.
  1376. @param keyName the name of the property to set. (This mustn't be an empty string)
  1377. @param value the new value to set it to
  1378. @see removeComponentProperty
  1379. */
  1380. void setComponentProperty (const String& keyName, const String& value) throw();
  1381. /** Sets a named property to an integer.
  1382. @param keyName the name of the property to set. (This mustn't be an empty string)
  1383. @param value the new value to set it to
  1384. @see removeComponentProperty
  1385. */
  1386. void setComponentProperty (const String& keyName, const int value) throw();
  1387. /** Sets a named property to a double.
  1388. @param keyName the name of the property to set. (This mustn't be an empty string)
  1389. @param value the new value to set it to
  1390. @see removeComponentProperty
  1391. */
  1392. void setComponentProperty (const String& keyName, const double value) throw();
  1393. /** Sets a named property to a boolean.
  1394. @param keyName the name of the property to set. (This mustn't be an empty string)
  1395. @param value the new value to set it to
  1396. @see removeComponentProperty
  1397. */
  1398. void setComponentProperty (const String& keyName, const bool value) throw();
  1399. /** Sets a named property to a colour.
  1400. @param keyName the name of the property to set. (This mustn't be an empty string)
  1401. @param newColour the new colour to set it to
  1402. @see removeComponentProperty
  1403. */
  1404. void setComponentProperty (const String& keyName, const Colour& newColour) throw();
  1405. /** Deletes a named component property.
  1406. @param keyName the name of the property to delete. (This mustn't be an empty string)
  1407. @see setComponentProperty, getComponentProperty
  1408. */
  1409. void removeComponentProperty (const String& keyName) throw();
  1410. /** Returns the complete set of properties that have been set for this component.
  1411. If no properties have been set, this will return a null pointer.
  1412. @see getComponentProperty, setComponentProperty
  1413. */
  1414. PropertySet* getComponentProperties() const throw() { return propertySet_; }
  1415. //==============================================================================
  1416. /** Looks for a colour that has been registered with the given colour ID number.
  1417. If a colour has been set for this ID number using setColour(), then it is
  1418. returned. If none has been set, the method will try calling the component's
  1419. LookAndFeel class's findColour() method. If none has been registered with the
  1420. look-and-feel either, it will just return black.
  1421. The colour IDs for various purposes are stored as enums in the components that
  1422. they are relevent to - for an example, see Slider::ColourIds,
  1423. Label::ColourIds, TextEditor::ColourIds, TreeView::ColourIds, etc.
  1424. @see setColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
  1425. */
  1426. const Colour findColour (const int colourId, const bool inheritFromParent = false) const throw();
  1427. /** Registers a colour to be used for a particular purpose.
  1428. Changing a colour will cause a synchronous callback to the colourChanged()
  1429. method, which your component can override if it needs to do something when
  1430. colours are altered.
  1431. For more details about colour IDs, see the comments for findColour().
  1432. @see findColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
  1433. */
  1434. void setColour (const int colourId, const Colour& colour);
  1435. /** If a colour has been set with setColour(), this will remove it.
  1436. This allows you to make a colour revert to its default state.
  1437. */
  1438. void removeColour (const int colourId);
  1439. /** Returns true if the specified colour ID has been explicitly set for this
  1440. component using the setColour() method.
  1441. */
  1442. bool isColourSpecified (const int colourId) const throw();
  1443. /** This looks for any colours that have been specified for this component,
  1444. and copies them to the specified target component.
  1445. */
  1446. void copyAllExplicitColoursTo (Component& target) const throw();
  1447. /** This method is called when a colour is changed by the setColour() method.
  1448. @see setColour, findColour
  1449. */
  1450. virtual void colourChanged();
  1451. //==============================================================================
  1452. /** Returns the underlying native window handle for this component.
  1453. This is platform-dependent and strictly for power-users only!
  1454. */
  1455. void* getWindowHandle() const throw();
  1456. /** When created, each component is given a number to uniquely identify it.
  1457. The number is incremented each time a new component is created, so it's a more
  1458. unique way of identifying a component than using its memory location (which
  1459. may be reused after the component is deleted, of course).
  1460. */
  1461. uint32 getComponentUID() const throw() { return componentUID; }
  1462. //==============================================================================
  1463. juce_UseDebuggingNewOperator
  1464. private:
  1465. //==============================================================================
  1466. friend class ComponentPeer;
  1467. friend class InternalDragRepeater;
  1468. static Component* currentlyFocusedComponent;
  1469. static Component* componentUnderMouse;
  1470. //==============================================================================
  1471. String componentName_;
  1472. Component* parentComponent_;
  1473. uint32 componentUID;
  1474. Rectangle bounds_;
  1475. unsigned short numDeepMouseListeners;
  1476. Array <Component*> childComponentList_;
  1477. LookAndFeel* lookAndFeel_;
  1478. MouseCursor cursor_;
  1479. ImageEffectFilter* effect_;
  1480. Image* bufferedImage_;
  1481. VoidArray* mouseListeners_;
  1482. VoidArray* keyListeners_;
  1483. VoidArray* componentListeners_;
  1484. PropertySet* propertySet_;
  1485. struct ComponentFlags
  1486. {
  1487. bool hasHeavyweightPeerFlag : 1;
  1488. bool visibleFlag : 1;
  1489. bool opaqueFlag : 1;
  1490. bool ignoresMouseClicksFlag : 1;
  1491. bool allowChildMouseClicksFlag : 1;
  1492. bool wantsFocusFlag : 1;
  1493. bool isFocusContainerFlag : 1;
  1494. bool dontFocusOnMouseClickFlag : 1;
  1495. bool alwaysOnTopFlag : 1;
  1496. bool bufferToImageFlag : 1;
  1497. bool bringToFrontOnClickFlag : 1;
  1498. bool repaintOnMouseActivityFlag : 1;
  1499. bool draggingFlag : 1;
  1500. bool mouseOverFlag : 1;
  1501. bool mouseInsideFlag : 1;
  1502. bool currentlyModalFlag : 1;
  1503. bool isDisabledFlag : 1;
  1504. bool childCompFocusedFlag : 1;
  1505. };
  1506. union
  1507. {
  1508. uint32 componentFlags_;
  1509. ComponentFlags flags;
  1510. };
  1511. //==============================================================================
  1512. void internalMouseEnter (int x, int y, const int64 time);
  1513. void internalMouseExit (int x, int y, const int64 time);
  1514. void internalMouseDown (int x, int y);
  1515. void internalMouseUp (const int oldModifiers, int x, int y, const int64 time);
  1516. void internalMouseDrag (int x, int y, const int64 time);
  1517. void internalMouseMove (int x, int y, const int64 time);
  1518. void internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time);
  1519. void internalBroughtToFront();
  1520. void internalFocusGain (const FocusChangeType cause);
  1521. void internalFocusLoss (const FocusChangeType cause);
  1522. void internalChildFocusChange (FocusChangeType cause);
  1523. void internalModalInputAttempt();
  1524. bool internalKeyPress (const int key, const juce_wchar textCharacter);
  1525. bool internalKeyStateChanged();
  1526. void internalModifierKeysChanged();
  1527. void internalChildrenChanged();
  1528. void internalHierarchyChanged();
  1529. void internalFilesDropped (const int x, const int y, const StringArray& files);
  1530. void internalUpdateMouseCursor (const bool forcedUpdate) throw();
  1531. void sendMovedResizedMessages (const bool wasMoved, const bool wasResized);
  1532. void repaintParent() throw();
  1533. void sendFakeMouseMove() const;
  1534. void takeKeyboardFocus (FocusChangeType cause);
  1535. void grabFocusInternal (FocusChangeType cause, const bool canTryParent = true);
  1536. static void giveAwayFocus();
  1537. void sendEnablementChangeMessage();
  1538. static void* runModalLoopCallback (void*);
  1539. void subtractObscuredRegions (RectangleList& result,
  1540. const int deltaX, const int deltaY,
  1541. const Rectangle& clipRect,
  1542. const Component* const compToAvoid) const throw();
  1543. void clipObscuredRegions (Graphics& g, const Rectangle& clipRect,
  1544. const int deltaX, const int deltaY) const throw();
  1545. // how much of the component is not off the edges of its parents
  1546. const Rectangle getUnclippedArea() const;
  1547. void sendVisibilityChangeMessage();
  1548. // components aren't allowed to have copy constructors, as this would mess up parent
  1549. // hierarchies. You might need to give your subclasses a private dummy constructor like
  1550. // this one to avoid compiler warnings.
  1551. Component (const Component&);
  1552. const Component& operator= (const Component&);
  1553. protected:
  1554. /** @internal */
  1555. virtual void internalRepaint (int x, int y, int w, int h);
  1556. virtual ComponentPeer* createNewPeer (int styleFlags, void* nativeWindowToAttachTo);
  1557. /** Overridden from the MessageListener parent class.
  1558. You can override this if you really need to, but be sure to pass your unwanted messages up
  1559. to this base class implementation, as the Component class needs to send itself messages
  1560. to work properly.
  1561. */
  1562. void handleMessage (const Message&);
  1563. };
  1564. #endif // __JUCE_COMPONENT_JUCEHEADER__