ComponentPeer Class Reference

The base class for window objects that wrap a component as a real operating system object. More...

List of all members.

Public Types

enum  StyleFlags {
  windowAppearsOnTaskbar = (1 << 0), windowIsTemporary = (1 << 1), windowIgnoresMouseClicks = (1 << 2), windowHasTitleBar = (1 << 3),
  windowIsResizable = (1 << 4), windowHasMinimiseButton = (1 << 5), windowHasMaximiseButton = (1 << 6), windowHasCloseButton = (1 << 7),
  windowHasDropShadow = (1 << 8), windowRepaintedExplictly = (1 << 9), windowIgnoresKeyPresses = (1 << 10), windowIsSemiTransparent = (1 << 31)
}
 

A combination of these flags is passed to the ComponentPeer constructor.

More...

Public Member Functions

 ComponentPeer (Component *component, int styleFlags) throw ()
 Creates a peer.
virtual ~ComponentPeer ()
 Destructor.
ComponentgetComponent () const throw ()
 Returns the component being represented by this peer.
int getStyleFlags () const throw ()
 Returns the set of style flags that were set when the window was created.
virtual void * getNativeHandle () const =0
 Returns the raw handle to whatever kind of window is being used.
virtual void setVisible (bool shouldBeVisible)=0
 Shows or hides the window.
virtual void setTitle (const String &title)=0
 Changes the title of the window.
virtual void setPosition (int x, int y)=0
 Moves the window without changing its size.
virtual void setSize (int w, int h)=0
 Resizes the window without changing its position.
virtual void setBounds (int x, int y, int w, int h, bool isNowFullScreen)=0
 Moves and resizes the window.
virtual const Rectangle< int > getBounds () const =0
 Returns the current position and size of the window.
virtual const Point< int > getScreenPosition () const =0
 Returns the x-position of this window, relative to the screen's origin.
virtual const Point< int > relativePositionToGlobal (const Point< int > &relativePosition)=0
 Converts a position relative to the top-left of this component to screen co-ordinates.
virtual const Point< int > globalPositionToRelative (const Point< int > &screenPosition)=0
 Converts a screen co-ordinate to a position relative to the top-left of this component.
virtual void setMinimised (bool shouldBeMinimised)=0
 Minimises the window.
virtual bool isMinimised () const =0
 True if the window is currently minimised.
virtual void setFullScreen (bool shouldBeFullScreen)=0
 Enable/disable fullscreen mode for the window.
virtual bool isFullScreen () const =0
 True if the window is currently full-screen.
void setNonFullScreenBounds (const Rectangle< int > &newBounds) throw ()
 Sets the size to restore to if fullscreen mode is turned off.
const Rectangle< int > & getNonFullScreenBounds () const throw ()
 Returns the size to restore to if fullscreen mode is turned off.
virtual void setIcon (const Image &newIcon)=0
 Attempts to change the icon associated with this window.
void setConstrainer (ComponentBoundsConstrainer *newConstrainer) throw ()
 Sets a constrainer to use if the peer can resize itself.
ComponentBoundsConstrainergetConstrainer () const throw ()
 Returns the current constrainer, if one has been set.
virtual bool contains (const Point< int > &position, bool trueIfInAChildWindow) const =0
 Checks if a point is in the window.
virtual const BorderSize getFrameSize () const =0
 Returns the size of the window frame that's around this window.
void handleMovedOrResized ()
 This is called when the window's bounds change.
void handleScreenSizeChange ()
 This is called if the screen resolution changes.
void handlePaint (LowLevelGraphicsContext &contextToPaintTo)
 This is called to repaint the component into the given context.
virtual bool setAlwaysOnTop (bool alwaysOnTop)=0
 Sets this window to either be always-on-top or normal.
virtual void toFront (bool makeActive)=0
 Brings the window to the top, optionally also giving it focus.
virtual void toBehind (ComponentPeer *other)=0
 Moves the window to be just behind another one.
void handleBroughtToFront ()
 Called when the window is brought to the front, either by the OS or by a call to toFront().
virtual bool isFocused () const =0
 True if the window has the keyboard focus.
virtual void grabFocus ()=0
 Tries to give the window keyboard focus.
virtual void textInputRequired (const Point< int > &position)=0
 Tells the window that text input may be required at the given position.
void handleFocusGain ()
 Called when the window gains keyboard focus.
void handleFocusLoss ()
 Called when the window loses keyboard focus.
ComponentgetLastFocusedSubcomponent () const throw ()
bool handleKeyPress (int keyCode, juce_wchar textCharacter)
 Called when a key is pressed.
bool handleKeyUpOrDown (bool isKeyDown)
 Called whenever a key is pressed or released.
void handleModifierKeysChange ()
 Called whenever a modifier key is pressed or released.
TextInputTargetfindCurrentTextInputTarget ()
 Returns the currently focused TextInputTarget, or null if none is found.
virtual void repaint (int x, int y, int w, int h)=0
 Invalidates a region of the window to be repainted asynchronously.
virtual void performAnyPendingRepaintsNow ()=0
 This can be called (from the message thread) to cause the immediate redrawing of any areas of this window that need repainting.
void handleMouseEvent (int touchIndex, const Point< int > &positionWithinPeer, const ModifierKeys &newMods, int64 time)
void handleMouseWheel (int touchIndex, const Point< int > &positionWithinPeer, int64 time, float x, float y)
void handleUserClosingWindow ()
void handleFileDragMove (const StringArray &files, const Point< int > &position)
void handleFileDragExit (const StringArray &files)
void handleFileDragDrop (const StringArray &files, const Point< int > &position)
void clearMaskedRegion () throw ()
 Resets the masking region.
void addMaskedRegion (int x, int y, int w, int h) throw ()
 Adds a rectangle to the set of areas not to paint over.
virtual const StringArray getAvailableRenderingEngines () throw ()
virtual int getCurrentRenderingEngine () throw ()
virtual void setCurrentRenderingEngine (int index) throw ()

Static Public Member Functions

static int getNumPeers () throw ()
 Returns the number of currently-active peers.
static ComponentPeergetPeer (int index) throw ()
 Returns one of the currently-active peers.
static bool isValidPeer (const ComponentPeer *peer) throw ()
 Checks if this peer object is valid.
static void bringModalComponentToFront ()

Static Protected Member Functions

static void updateCurrentModifiers () throw ()

Protected Attributes

Component *const component
const int styleFlags
RectangleList maskedRegion
Rectangle< int > lastNonFullscreenBounds
uint32 lastPaintTime
ComponentBoundsConstrainerconstrainer

Detailed Description

The base class for window objects that wrap a component as a real operating system object.

This is an abstract base class - the platform specific code contains default implementations of it that create and manage windows.

See also:
Component::createNewPeer

Member Enumeration Documentation

A combination of these flags is passed to the ComponentPeer constructor.

Enumerator:
windowAppearsOnTaskbar 

Indicates that the window should have a corresponding entry on the taskbar (ignored on MacOSX).

windowIsTemporary 

Indicates that the window is a temporary popup, like a menu, tooltip, etc.

windowIgnoresMouseClicks 

Indicates that the window should let mouse clicks pass through it (may not be possible on some platforms).

windowHasTitleBar 

Indicates that the window should have a normal OS-specific title bar and frame\.

if not specified, the window will be borderless.

windowIsResizable 

Indicates that the window should have a resizable border.

windowHasMinimiseButton 

Indicates that if the window has a title bar, it should have a minimise button on it.

windowHasMaximiseButton 

Indicates that if the window has a title bar, it should have a maximise button on it.

windowHasCloseButton 

Indicates that if the window has a title bar, it should have a close button on it.

windowHasDropShadow 

Indicates that the window should have a drop-shadow (this may not be possible on all platforms).

windowRepaintedExplictly 

Not intended for public use - this tells a window not to do its own repainting, but only to repaint when the performAnyPendingRepaintsNow() method is called.

windowIgnoresKeyPresses 

Tells the window not to catch any keypresses.

This can be used for things like plugin windows, to stop them interfering with the host's shortcut keys

windowIsSemiTransparent 

Not intended for public use - makes a window transparent.


Constructor & Destructor Documentation

ComponentPeer::ComponentPeer ( Component component,
int  styleFlags 
) throw ()

Creates a peer.

The component is the one that we intend to represent, and the style flags are a combination of the values in the StyleFlags enum

virtual ComponentPeer::~ComponentPeer (  )  [virtual]

Destructor.


Member Function Documentation

Component* ComponentPeer::getComponent (  )  const throw ()

Returns the component being represented by this peer.

int ComponentPeer::getStyleFlags (  )  const throw ()

Returns the set of style flags that were set when the window was created.

See also:
Component::addToDesktop
virtual void* ComponentPeer::getNativeHandle (  )  const [pure virtual]

Returns the raw handle to whatever kind of window is being used.

On windows, this is probably a HWND, on the mac, it's likely to be a WindowRef, but rememeber there's no guarantees what you'll get back.

virtual void ComponentPeer::setVisible ( bool  shouldBeVisible  )  [pure virtual]

Shows or hides the window.

virtual void ComponentPeer::setTitle ( const String title  )  [pure virtual]

Changes the title of the window.

virtual void ComponentPeer::setPosition ( int  x,
int  y 
) [pure virtual]

Moves the window without changing its size.

If the native window is contained in another window, then the co-ordinates are relative to the parent window's origin, not the screen origin.

This should result in a callback to handleMovedOrResized().

virtual void ComponentPeer::setSize ( int  w,
int  h 
) [pure virtual]

Resizes the window without changing its position.

This should result in a callback to handleMovedOrResized().

virtual void ComponentPeer::setBounds ( int  x,
int  y,
int  w,
int  h,
bool  isNowFullScreen 
) [pure virtual]

Moves and resizes the window.

If the native window is contained in another window, then the co-ordinates are relative to the parent window's origin, not the screen origin.

This should result in a callback to handleMovedOrResized().

virtual const Rectangle<int> ComponentPeer::getBounds (  )  const [pure virtual]

Returns the current position and size of the window.

If the native window is contained in another window, then the co-ordinates are relative to the parent window's origin, not the screen origin.

virtual const Point<int> ComponentPeer::getScreenPosition (  )  const [pure virtual]

Returns the x-position of this window, relative to the screen's origin.

virtual const Point<int> ComponentPeer::relativePositionToGlobal ( const Point< int > &  relativePosition  )  [pure virtual]

Converts a position relative to the top-left of this component to screen co-ordinates.

virtual const Point<int> ComponentPeer::globalPositionToRelative ( const Point< int > &  screenPosition  )  [pure virtual]

Converts a screen co-ordinate to a position relative to the top-left of this component.

virtual void ComponentPeer::setMinimised ( bool  shouldBeMinimised  )  [pure virtual]

Minimises the window.

virtual bool ComponentPeer::isMinimised (  )  const [pure virtual]

True if the window is currently minimised.

virtual void ComponentPeer::setFullScreen ( bool  shouldBeFullScreen  )  [pure virtual]

Enable/disable fullscreen mode for the window.

virtual bool ComponentPeer::isFullScreen (  )  const [pure virtual]

True if the window is currently full-screen.

void ComponentPeer::setNonFullScreenBounds ( const Rectangle< int > &  newBounds  )  throw ()

Sets the size to restore to if fullscreen mode is turned off.

const Rectangle<int>& ComponentPeer::getNonFullScreenBounds (  )  const throw ()

Returns the size to restore to if fullscreen mode is turned off.

virtual void ComponentPeer::setIcon ( const Image newIcon  )  [pure virtual]

Attempts to change the icon associated with this window.

void ComponentPeer::setConstrainer ( ComponentBoundsConstrainer newConstrainer  )  throw ()

Sets a constrainer to use if the peer can resize itself.

The constrainer won't be deleted by this object, so the caller must manage its lifetime.

ComponentBoundsConstrainer* ComponentPeer::getConstrainer (  )  const throw ()

Returns the current constrainer, if one has been set.

virtual bool ComponentPeer::contains ( const Point< int > &  position,
bool  trueIfInAChildWindow 
) const [pure virtual]

Checks if a point is in the window.

Coordinates are relative to the top-left of this window. If trueIfInAChildWindow is false, then this returns false if the point is actually inside a child of this window.

virtual const BorderSize ComponentPeer::getFrameSize (  )  const [pure virtual]

Returns the size of the window frame that's around this window.

Whether or not the window has a normal window frame depends on the flags that were set when the window was created by Component::addToDesktop()

void ComponentPeer::handleMovedOrResized (  ) 

This is called when the window's bounds change.

A peer implementation must call this when the window is moved and resized, so that this method can pass the message on to the component.

void ComponentPeer::handleScreenSizeChange (  ) 

This is called if the screen resolution changes.

A peer implementation must call this if the monitor arrangement changes or the available screen size changes.

void ComponentPeer::handlePaint ( LowLevelGraphicsContext contextToPaintTo  ) 

This is called to repaint the component into the given context.

virtual bool ComponentPeer::setAlwaysOnTop ( bool  alwaysOnTop  )  [pure virtual]

Sets this window to either be always-on-top or normal.

Some kinds of window might not be able to do this, so should return false.

virtual void ComponentPeer::toFront ( bool  makeActive  )  [pure virtual]

Brings the window to the top, optionally also giving it focus.

virtual void ComponentPeer::toBehind ( ComponentPeer other  )  [pure virtual]

Moves the window to be just behind another one.

void ComponentPeer::handleBroughtToFront (  ) 

Called when the window is brought to the front, either by the OS or by a call to toFront().

virtual bool ComponentPeer::isFocused (  )  const [pure virtual]

True if the window has the keyboard focus.

virtual void ComponentPeer::grabFocus (  )  [pure virtual]

Tries to give the window keyboard focus.

virtual void ComponentPeer::textInputRequired ( const Point< int > &  position  )  [pure virtual]

Tells the window that text input may be required at the given position.

This may cause things like a virtual on-screen keyboard to appear, depending on the OS.

void ComponentPeer::handleFocusGain (  ) 

Called when the window gains keyboard focus.

void ComponentPeer::handleFocusLoss (  ) 

Called when the window loses keyboard focus.

Component* ComponentPeer::getLastFocusedSubcomponent (  )  const throw ()
bool ComponentPeer::handleKeyPress ( int  keyCode,
juce_wchar  textCharacter 
)

Called when a key is pressed.

For keycode info, see the KeyPress class. Returns true if the keystroke was used.

bool ComponentPeer::handleKeyUpOrDown ( bool  isKeyDown  ) 

Called whenever a key is pressed or released.

Returns true if the keystroke was used.

void ComponentPeer::handleModifierKeysChange (  ) 

Called whenever a modifier key is pressed or released.

TextInputTarget* ComponentPeer::findCurrentTextInputTarget (  ) 

Returns the currently focused TextInputTarget, or null if none is found.

virtual void ComponentPeer::repaint ( int  x,
int  y,
int  w,
int  h 
) [pure virtual]

Invalidates a region of the window to be repainted asynchronously.

virtual void ComponentPeer::performAnyPendingRepaintsNow (  )  [pure virtual]

This can be called (from the message thread) to cause the immediate redrawing of any areas of this window that need repainting.

You shouldn't ever really need to use this, it's mainly for special purposes like supporting audio plugins where the host's event loop is out of our control.

void ComponentPeer::handleMouseEvent ( int  touchIndex,
const Point< int > &  positionWithinPeer,
const ModifierKeys newMods,
int64  time 
)
void ComponentPeer::handleMouseWheel ( int  touchIndex,
const Point< int > &  positionWithinPeer,
int64  time,
float  x,
float  y 
)
void ComponentPeer::handleUserClosingWindow (  ) 
void ComponentPeer::handleFileDragMove ( const StringArray files,
const Point< int > &  position 
)
void ComponentPeer::handleFileDragExit ( const StringArray files  ) 
void ComponentPeer::handleFileDragDrop ( const StringArray files,
const Point< int > &  position 
)
void ComponentPeer::clearMaskedRegion (  )  throw ()

Resets the masking region.

The subclass should call this every time it's about to call the handlePaint method.

See also:
addMaskedRegion
void ComponentPeer::addMaskedRegion ( int  x,
int  y,
int  w,
int  h 
) throw ()

Adds a rectangle to the set of areas not to paint over.

A component can call this on its peer during its paint() method, to signal that the painting code should ignore a given region. The reason for this is to stop embedded windows (such as OpenGL) getting painted over.

The masked region is cleared each time before a paint happens, so a component will have to make sure it calls this every time it's painted.

static int ComponentPeer::getNumPeers (  )  throw () [static]

Returns the number of currently-active peers.

See also:
getPeer
static ComponentPeer* ComponentPeer::getPeer ( int  index  )  throw () [static]

Returns one of the currently-active peers.

See also:
getNumPeers
static bool ComponentPeer::isValidPeer ( const ComponentPeer peer  )  throw () [static]

Checks if this peer object is valid.

See also:
getNumPeers
static void ComponentPeer::bringModalComponentToFront (  )  [static]
virtual const StringArray ComponentPeer::getAvailableRenderingEngines (  )  throw () [virtual]
virtual int ComponentPeer::getCurrentRenderingEngine (  )  throw () [virtual]
virtual void ComponentPeer::setCurrentRenderingEngine ( int  index  )  throw () [virtual]
static void ComponentPeer::updateCurrentModifiers (  )  throw () [static, protected]

Member Data Documentation

Component* const ComponentPeer::component [protected]
const int ComponentPeer::styleFlags [protected]

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:11 2010 for JUCE by  doxygen 1.6.3