JUCE API document - Chinese version - All done!

OK, 做个广告。

欢迎访问JUCE类库中文技术支持:

http://blog.sina.com.cn/jucecn

1 Like

[size=150]Component 组件类[/size]

所有JUCE用户界面对象的基类。更多…

继承自:MouseListener

继承给:ActiveXControlComponent, AudioDeviceSelectorComponent, AudioProcessorEditor, BubbleComponent, Button, CallOutBox, CarbonViewWrapperComponent, CodeEditorComponent, ColourSelector, ComboBox, Drawable, FileBrowserComponent, FileChooserDialogBox::ContentComponent, FilenameComponent, FilePreviewComponent, FileSearchPathListComponent, GroupComponent, KeyMappingEditorComponent, Label, LassoComponent< SelectableItemType >, ListBox, MagnifierComponent, MenuBarComponent, MidiKeyboardComponent, MultiDocumentPanel, NSViewComponent, OpenGLComponent, PluginListComponent, PopupMenuCustomComponent, PreferencesPanel, ProgressBar, PropertyComponent, PropertyPanel, ResizableBorderComponent, ResizableCornerComponent, ScrollBar, Slider, SplashScreen, StretchableLayoutResizerBar, SystemTrayIconComponent, TabbedButtonBar, TabbedComponent, TableHeaderComponent, TextEditor, Toolbar, ToolbarItemPalette, TooltipWindow, TopLevelWindow, TreeView, Viewport, and WebBrowserComponent.

所有成员

class BailOutChecker
该类密切注视一个或两个组件,在组件被销毁时进行检验。更多…
class SafePointer
保存某些组件类型的指针,当该组件被销毁时自动将其置零。更多…

Public类型

enum FocusChangeType { focusChangedByMouseClick, focusChangedByTabKey, focusChangedDirectly }

被focusChanged()和focusLost()等函数所使用的枚举常量。

更多…

1 Like

public成员函数

Component ()
创建一个组件。

virtual ActionListener::~ActionListener ~Component ()
析构函数。
Component (const String &componentName)
创建一个组件,同时设置其名称。
const String & getName () const throw ()
返回此组件的名称。
virtual void setName (const String &newName)
设置此组件的名称。
virtual void setVisible (bool shouldBeVisible)
设置此组件可见与否。
bool isVisible () const throw ()
检测该组件是否可见。
virtual void visibilityChanged ()
组件可见与否发生变化时,自动调用此函数。
bool isShowing () const
检测该组件和它的所有上级组件是否可视。
virtual void addToDesktop (int windowStyleFlags, void *nativeWindowToAttachTo=0)
使该组件显示为一个桌面窗口。
void removeFromDesktop ()
如果该组件正显示在桌面上,此函数将隐藏它。
bool isOnDesktop () const throw ()
如果该组件当前显示在桌面上,则返回true。
ComponentPeer * getPeer () const
返回包含该组件的重量级窗口。
virtual void userTriedToCloseWindow ()
组件位于桌面的前提下,当操作系统要关闭该窗口时,将自动调用此函数。
virtual void minimisationStateChanged (bool isNowMinimised)
桌面组件最小化或取消最小化时,自动调用此函数。
void toFront (bool shouldAlsoGainFocus)
将该组件置于同级组件的最前面。
void toBack ()
将该组件置于同级组件的最后面(改变Z-顺序)。
void toBehind (Component *other)
将该组件置于参数组件的后面(改变Z-顺序)。
void setAlwaysOnTop (bool shouldStayOnTop)
设置该组件是否始终位于同级组件的最前面。
bool isAlwaysOnTop () const throw ()
如果该组件已设置为始终位于同级组件的最前面,则返回true。
int getX () const throw ()
返回该组件的左边缘x坐标。
int getY () const throw ()
返回该组件顶边缘的y坐标。
int getWidth () const throw ()
返回组件的宽度(单位:像素)。
int getHeight () const throw ()
返回组件的高度(单位:像素)。
int getRight () const throw ()
返回该组件右边缘的x坐标。
const Point< int > getPosition () const throw ()
返回该组件的左上角位置。返回类型为Point。
int getBottom () const throw ()
返回该组件底边缘的y坐标。
const Rectangle< int > & getBounds () const throw ()
返回此组件的边框。
const Rectangle< int > getLocalBounds () const throw ()
返回组件的边界,相对于其自身的原点。
const Rectangle< int > getBoundsInParent () const throw ()
返回此组件所覆盖的父级组件的区域。
void getVisibleArea (RectangleList &result, bool includeSiblings) const
返回此组件未被其它组件所遮盖的、且不透明的区域。
int getScreenX () const
返回此组件相对于屏幕原点的X坐标。
int getScreenY () const
返回此组件相对于屏幕原点的Y坐标。
const Point< int > getScreenPosition () const
返回此组件的左上角相对于屏幕左上角的位置。
const Rectangle< int > getScreenBounds () const
返回此组件相对于屏幕左上角的边界。
const Point< int > getLocalPoint (const Component *sourceComponent, const Point< int > &pointRelativeToSourceComponent) const
根据此组件的坐标空间转换一个坐标值(Point)。
const Rectangle< int > getLocalArea (const Component *sourceComponent, const Rectangle< int > &areaRelativeToSourceComponent) const
根据此组件的坐标空间转换一个矩形区域。
const Point< int > localPointToGlobal (const Point< int > &localPoint) const
将此组件的原点转换为屏幕坐标。
const Rectangle< int > localAreaToGlobal (const Rectangle< int > &localArea) const
将此组件的矩形空间转换为屏幕坐标
void setTopLeftPosition (int x, int y)
将此组件移动到新的位置。
void setTopRightPosition (int x, int y)
将此组件移动到新的位置。
void setSize (int newWidth, int newHeight)
更改组件的大小。
void setBounds (int x, int y, int width, int height)
改变组件的位置和大小。
void setBounds (const Rectangle< int > &newBounds)
改变组件的位置和大小。
void setBoundsRelative (float proportionalX, float proportionalY, float proportionalWidth, float proportionalHeight)
根据父级组件的大小和区域更改此组件的位置和大小。
void setBoundsInset (const BorderSize &borders)
基于四周的空间更改此组件的位置和大小。
void setBoundsToFit (int x, int y, int width, int height, const Justification &justification, bool onlyReduceInSize)
按给定的区域定位此组件,宽高比不变。
void setCentrePosition (int x, int y)
更改此组件的中心位置。
void setCentreRelative (float x, float y)
更改此组件的中心位置。
void centreWithSize (int width, int height)
更改此组件的大小,并位于父级组件的中心。
void setTransform (const AffineTransform &transform)
设置此组件的变换矩阵(缩放、旋转等等)。
const AffineTransform getTransform () const
返回此组件当前所设置的变换矩阵(缩放,旋转等等)。
bool isTransformed () const throw ()
如果此组件当前应用了缩放、旋转等转换,则返回true。
int proportionOfWidth (float proportion) const throw ()
返回此组件的宽度比例。
int proportionOfHeight (float proportion) const throw ()
返回此组件的高度比例。
int getParentWidth () const throw ()
返回此组件的父级组件的宽度。
int getParentHeight () const throw ()
返回此组件的父级组件的高度。
const Rectangle< int > getParentMonitorArea () const
返回包含此组件的显示器的屏幕坐标系。
int getNumChildComponents () const throw ()
返回此组件包含的子组件的个数。
Component * getChildComponent (int index) const throw ()
按索引值返回该组件所包含的某个子组件。
int getIndexOfChildComponent (const Component *child) const throw ()
返回此组件所包含的某个子组件的索引值。
void addChildComponent (Component *child, int zOrder=-1)
此组件添加一个子组件。
void addAndMakeVisible (Component *child, int zOrder=-1)
此组件添加一个子组件,如果子组件当前不可见,则使之可见。
void removeChildComponent (Component *childToRemove)
移除此组件所包含的某个子组件。
Component * removeChildComponent (int childIndexToRemove)
按索引值移除该组件所包含的某个子组件。
void removeAllChildren ()
移除该组件所包含的所有子组件。
void deleteAllChildren ()
移除该组件所包含的所有子组件,并销毁它们。
Component * getParentComponent () const throw ()
返回此组件的父级组件。
template
TargetClass * findParentComponentOfClass (TargetClass *const dummyParameter=0) const
按给定的类搜索父级组件。
Component * getTopLevelComponent () const throw ()
返回包含该组件及其父级组件的最顶级组件。
bool isParentOf (const Component *possibleChild) const throw ()
检测该组件是否为给定组件的父级组件。
virtual void parentHierarchyChanged ()
当此组件改变所隶属的父级组件时,自动调用此函数。
virtual void childrenChanged ()
当此组件添加或移除子组件时,自动调用此函数。
virtual bool hitTest (int x, int y)
检测给定的点是否位于此组件内。
void setInterceptsMouseClicks (bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) throw ()
改变hitTest()方法的参数,设置拦截鼠标点击事件。
void getInterceptsMouseClicks (bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const throw ()
获取鼠标点击拦截标记的当前状态。
bool contains (const Point< int > &localPoint)
如果给定的坐标点位于此组件或它的子组件之内,则返回true。
bool reallyContains (const Point< int > &localPoint, bool returnTrueIfWithinAChild)
如果给定的点位于此组件之内则返回true,同时考虑到任何重叠的同级组件。
Component * getComponentAt (int x, int y)
返回给定的点所位于的组件。
Component * getComponentAt (const Point< int > &position)
返回给定的点所位于的组件。
void repaint ()
标记整个组件需要重绘。
void repaint (int x, int y, int width, int height)
标记组件的某个区域需要重绘。
void repaint (const Rectangle< int > &area)
标记组件的某个区域需要重绘。
void setBufferedToImage (bool shouldBeBuffered)
设置该组件使用内部缓冲来优化重绘操作。
const Image createComponentSnapshot (const Rectangle< int > &areaToGrab, bool clipImageToComponentBounds=true)
生成此组件某个区域的屏幕快照。
void paintEntireComponent (Graphics &context, bool ignoreAlphaLevel)
用给定的绘图环境重绘此组件及其所有的子组件。
void setPaintingIsUnclipped (bool shouldPaintWithoutClipping) throw ()
此方法允许表明此组件在重绘时无需剪切图形环境。
void setComponentEffect (ImageEffectFilter *newEffect)
设置组件的外观。
ImageEffectFilter * getComponentEffect () const throw ()
返回此组件当前所设置的外观效果。
LookAndFeel & getLookAndFeel () const throw ()
获取该组件所使用的外观及感觉(look-and-feel)。
void setLookAndFeel (LookAndFeel *newLookAndFeel)
设置此组件的外观与感觉(Look-and-Feel)。
virtual void lookAndFeelChanged ()
当该组件所使用的外观与感觉发生变化时,自动调用此函数。
void sendLookAndFeelChange ()
设置此组件和它的所有子组件调用lookAndFeelChanged()方法。
void setOpaque (bool shouldBeOpaque)
设置不透明。
bool isOpaque () const throw ()
如果此组件为不透明的(无任何透明的区域),则返回true。
void setBroughtToFrontOnMouseClick (bool shouldBeBroughtToFront) throw ()
设置当鼠标点击时,此组件是否自动切换到最前面。
bool isBroughtToFrontOnMouseClick () const throw ()
如果鼠标点击时此组件自动切换到最前面,则返回true。
void setWantsKeyboardFocus (bool wantsFocus) throw ()
设置一个标志,以表明此组件是否需要键盘焦点。
bool getWantsKeyboardFocus () const throw ()
如果此组件对键盘焦点感兴趣,则返回true。
void setMouseClickGrabsKeyboardFocus (bool shouldGrabFocus)
设置点击此组件时是否拥有键盘焦点。
bool getMouseClickGrabsKeyboardFocus () const throw ()
返回setMouseClickGrabsKeyboardFocus()所设置的值。
void grabKeyboardFocus ()
试图使此组件拥有键盘焦点。
bool hasKeyboardFocus (bool trueIfChildIsFocused) const
如果此组件当前拥有键盘焦点则返回true。
void moveKeyboardFocusToSibling (bool moveToNext)
尝试将键盘焦点转移给下一个同级组件。
virtual KeyboardFocusTraverser * createFocusTraverser ()
创建一个KeyboardFocusTraverser对象以确定此组件传递焦点的逻辑。
int getExplicitFocusOrder () const
返回此组件的焦点顺序,如果已指定。
void setExplicitFocusOrder (int newFocusOrderIndex)
按索引值设置焦点转移的顺序。
void setFocusContainer (bool shouldBeFocusContainer) throw ()
设置此组件是否为焦点容器。
bool isFocusContainer () const throw ()
如果此组件为焦点容器,则返回true。
bool isEnabled () const throw ()
如果此组件及其所有的子组件为开启状态,则返回true。
void setEnabled (bool shouldBeEnabled)
启用或禁用此组件。
virtual void enablementChanged ()
启用或禁用此组件时自动调用此函数。
void setAlpha (float newAlpha)
更改此组件的透明度。
float getAlpha () const
返回此组件当前所设置的透明度。
void setMouseCursor (const MouseCursor &cursorType)
设置鼠标指针的外观(当鼠标指向该组件时)。
virtual const MouseCursor getMouseCursor ()
获取当前设置的鼠标指针外观(当鼠标指向该组件时)。
void updateMouseCursor () const
强制刷新当前的鼠标指针。
virtual void paint (Graphics &g)
重写此方法以绘制此组件的内容。
virtual void paintOverChildren (Graphics &g)
可重写此方法以绘制位于最前面的子组件。
virtual void mouseMove (const MouseEvent &e)
当鼠标在此组件中移动时,自动调用此函数。
virtual void mouseEnter (const MouseEvent &e)
当鼠标指针进入此组件时,自动调用此函数。
virtual void mouseExit (const MouseEvent &e)
当鼠标指针退出此组件时,自动调用此函数。
virtual void mouseDown (const MouseEvent &e)
当鼠标指针位于此组件并且点击某个鼠标键,尚未释放时,自动调用此函数。
virtual void mouseDrag (const MouseEvent &e)
当鼠标拖拽时,自动调用此函数。
virtual void mouseUp (const MouseEvent &e)
鼠标点击并释放某个鼠标按键时自动调用此函数。
virtual void mouseDoubleClick (const MouseEvent &e)
鼠标在此组件中双击时自动调用此函数。
virtual void mouseWheelMove (const MouseEvent &e, float wheelIncrementX, float wheelIncrementY)
转动鼠标滚轮键时自动调用此函数。
void setRepaintsOnMouseActivity (bool shouldRepaint) throw ()
鼠标指针进入或退出此组件时,自动重绘。
void addMouseListener (MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
绑定鼠标事件捕获器。
void removeMouseListener (MouseListener *listenerToRemove)
移除已经绑定的鼠标事件捕获器。
void addKeyListener (KeyListener *newListener)
添加此组件能够接收的按键事件捕获器。
void removeKeyListener (KeyListener *listenerToRemove)
移除已经绑定的按键捕获器。
virtual bool keyPressed (const KeyPress &key)
当按下某个键时,自动调用此函数。
virtual bool keyStateChanged (bool isKeyDown)
当按下或释放某个键时自动调用此函数。
virtual void modifierKeysChanged (const ModifierKeys &modifiers)
按下或释放某个功能键时自动调用此函数。
virtual void focusGained (FocusChangeType cause)
此组件拥有键盘焦点时自动此函数。
virtual void focusLost (FocusChangeType cause)
此组件失去键盘焦点时自动此函数。
virtual void focusOfChildComponentChanged (FocusChangeType cause)
此组件的子组件拥有或失去键盘焦点时自动调用此函数。
bool isMouseOver (bool includeChildren=false) const
如果鼠标指针位于此组件则返回true。
bool isMouseButtonDown () const throw ()
如果正按下鼠标的某个键,则返回true。
bool isMouseOverOrDragging () const throw ()
如果鼠标指针位于此组件,或者正在此组件中拖拽,则返回true。
const Point< int > getMouseXYRelative () const
返回鼠标指针的当前位置,相对于此组件的原点。
virtual void resized ()
此组件的大小发生变化时自动调用此函数。
virtual void moved ()
此组件的位置发生变化时自动调用此函数。
virtual void childBoundsChanged (Component *child)
当此组件的某个子组件的大小和位置发生变化时,自动调用此函数。
virtual void parentSizeChanged ()
当此组件的上一级父组件的大小发生变化时,自动调用此函数。
virtual void broughtToFront ()
当此组件位于其同级组件的最前面时,自动调用此函数。
void addComponentListener (ComponentListener *newListener)
添加一个捕获器以告知组件的隶属关系或位置发生变化。
void removeComponentListener (ComponentListener *listenerToRemove)
移除已经添加的组件捕获器。
void postCommandMessage (int commandId)
将某个消息发送给此组件。
virtual void handleCommandMessage (int commandId)
处理postCommandMessage()发送过来的消息。
int runModalLoop ()
进入模态(无限循环、自动置顶状态),直到循环终止。
void enterModalState (bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=0)
使此组件进入模态。
void exitModalState (int returnValue)
结束模态。
bool isCurrentlyModal () const throw ()
如果此组件当前为模态则返回true。
bool isCurrentlyBlockedByAnotherModalComponent () const
检测是否正有一个模态组件阻碍了此组件接收消息。
virtual bool canModalEventBeSentToComponent (const Component *targetComponent)
当组件为模态时,此函数允许给定组件依然可以接收消息。
virtual void inputAttemptWhenModal ()
在当前正有一个模态组件的前提下,如果尝试点击此组件,则自动调用此函数。
NamedValueSet & getProperties () throw ()
获取此组件的属性设置。
const NamedValueSet & getProperties () const throw ()
获取此组件的属性设置。
const Colour findColour (int colourId, bool inheritFromParent=false) const
查找已经注册使用的某个颜色。
void setColour (int colourId, const Colour &colour)
注册一个要使用的颜色。
void removeColour (int colourId)
如果某个颜色是setColour()所设置的,则移除之。
bool isColourSpecified (int colourId) const
如果给定的颜色由setColour()所设置,则返回true。
void copyAllExplicitColoursTo (Component &target) const
将此组件已经注册的颜色复制给其它组件。
virtual void colourChanged ()
当setColour()函数改变某个颜色时,自动调用此函数。
void * getWindowHandle () const
返回此组件潜在的本地窗口句柄。

1 Like

静态Public成员函数

static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent () throw ()
返回当前拥有键盘焦点的某个组件。
static void beginDragAutoRepeat (int millisecondsBetweenCallbacks)
确保鼠标拖拽时所产生的事件数据流无停滞。
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere () throw ()
如果正按下鼠标的某个键,则返回true。
static int JUCE_CALLTYPE getNumCurrentlyModalComponents () throw ()
返回当前处于模态的组件个数。
static Component *JUCE_CALLTYPE getCurrentlyModalComponent (int index=0) throw ()
返回当前处于模态的组件。

[size=150]详细说明[/size]

所有JUCE用户界面对象的基类。

枚举成员文档

enum Component::FocusChangeType
被focusChanged()和focusLost()等函数所使用的枚举常量。

枚举常量:
focusChangedByMouseClick
鼠标点击以改变焦点。

focusChangedByTabKey
按TAB键转移焦点。

focusChangedDirectly
使用grabKeyboardFocus()改变焦点。

构造函数和析构函数文档

Component::Component ( )
创建一个组件。

要让此组件实际显示出来,尚需:

将其添加到父级组件中,或者使用addToDesktop()方法使之成为桌面窗口。
设置其大小和位置。
使用setVisible()方法使之可见。
要明确其具有某种使用目的,往往需要派生该类的子类,或者使用JUCE类库中已经定义的该类的派生类(标签、按钮、组合框等等)。

virtual Component::~Component ( ) [virtual]
析构函数。

注意,当销毁某个组件时,它包含的所有子组件不会自动销毁。可使用delete()、deleteAndZero()、deleteAllChildren()等方法或ScopedPointers来管理其子组件。

如果所要销毁的组件是其它组件的子组件,那么在销毁期间,其父级组件将自动移除之,并且父级组件将自动调用childrenChanged()函数。此组件已经注册的所有ComponentListener对象也将自动调用ComponentListener::componentBeingDeleted()方法。

Component::Component ( const String & message componentName ) [explicit]
创建一个组件,同时设置其名称。

参见:
getName, setName

1 Like

成员函数文档

const String& Component::getName ( ) const throw ()
返回此组件的名称。

参见:
setName
virtual void Component::setName ( const String & message newName ) [virtual]
设置此组件的名称。

改变组件名称时,所有已经注册的ComponentListeners将自动收到一条ComponentListener::componentNameChanged()函数所产生的消息。

参见:
getName()
该类重写此函数:DocumentWindow

virtual void Component::setVisible ( bool shouldBeVisible ) [virtual]
设置此组件可见与否。

此方法将显示或隐藏此组件。注意,组件第一次创建时,默认是不可见的。同时,如果其父级组件不可见,那么无论如何,该组件均不可见。

此函数将调用对此有兴趣的组件捕获器的visibilityChanged()和componentVisibilityChanged()方法。

参数:
shouldBeVisible 是否显示此组件。
参见:
isVisible, isShowing, visibilityChanged, ComponentListener::componentVisibilityChanged
以下函数中引用了此函数:LassoComponent< SelectableItemType >::dragLasso(), LassoComponent< SelectableItemType >::endLasso()

bool Component::isVisible ( ) const throw ()
检测该组件是否可见。

注意:JUCE组件的可见和可视是两个概念。可见并不一定出现在屏幕上。而可视则是实际出现在屏幕上,能够看到该组件。而且,组件是否可见,还取决于其父级组件当前是否已设置为可见。可使用isShowing()方法来确定该组件当前是否可视。

参见:
isShowing, setVisible
virtual void Component::visibilityChanged ( ) [virtual]
组件可见与否发生变化时,自动调用此函数。

参见:
setVisible, isVisible
该类重写此函数:Button, ListBox, ProgressBar, WebBrowserComponent, ResizableWindow, TopLevelWindow

bool Component::isShowing ( ) const
检测该组件和它的所有上级组件是否可视。

返回:
仅在此组件及其所有的父级组件均为可见状态时,才返回true。
参见:
isVisible
以下函数中引用了此函数:CarbonViewWrapperComponent::componentVisibilityChanged()

virtual void Component::addToDesktop ( int windowStyleFlags,
void * nativeWindowToAttachTo = 0
) [virtual]
使该组件显示为一个桌面窗口。

注意,调用此函数要确保该组件已设置为不透明的(使用setOpaque()方法)。如果组件是透明的,或者半透明的,则操作系统的窗口机制将尝试创建一个特殊的透明区域,此举将消耗大量的CPU和内存,并且在某些平台下,可能无法实现透明效果,或者运行出错。

如果该组件是其它组件的子组件,则调用此函数时将首先从父级组件中移除之。同样,如果将桌面上的某个组件置于其它组件中,则首先从桌面上移除之。

参数:
windowStyleFlags ComponentPeer::StyleFlags枚举常量,用于指定窗口的各项属性。
nativeWindowToAttachTo 允许传递一个操作系统的本地窗口,以用来放置此组件。Windows系统下,此参数为一个窗口句柄HWND,MAC系统下为一个HIViewRef。此参数不一定支持所有的操作系统,在不确定将出现什么结果时,最好采用默认的参数0。
参见:
removeFromDesktop, isOnDesktop, userTriedToCloseWindow, getPeer, ComponentPeer::setMinimised, ComponentPeer::StyleFlags, ComponentPeer::getStyleFlags, ComponentPeer::setFullScreen
该类重写此函数:TopLevelWindow

void Component::removeFromDesktop ( )
如果该组件正显示在桌面上,此函数将隐藏它。

也可使用setVisible()临时性的隐藏桌面窗口,但setVisible()不会释放所占用的系统资源。因此,若隐藏的同时打算一并释放所占用的系统资源,则建议使用本函数。

参见:
addToDesktop, isOnDesktop
bool Component::isOnDesktop ( ) const throw ()
如果该组件当前显示在桌面上,则返回true。

参见:
addToDesktop, removeFromDesktop
以下函数中引用了此函数:TopLevelWindow::isUsingNativeTitleBar()

ComponentPeer* Component::getPeer ( ) const
返回包含该组件的重量级窗口。

如果此组件位于桌面上,将返回它所使用的窗口对象。否则,返回其顶级父级组件的窗口。

如果应用程序连一个桌面组件都没有,则返回值也许为0。

参见:
addToDesktop, isOnDesktop
virtual void Component::userTriedToCloseWindow ( ) [virtual]
组件位于桌面的前提下,当操作系统要关闭该窗口时,将自动调用此函数。

此函数将发出关闭窗口的信号,无论是用户点击关闭按钮,还是操作系统强行关闭窗口。默认情况下,触发断言命令以提示该组件将发生某些事情,但可以重写此函数以忽略此命令。

重写此函数的类: AlertWindow, DocumentWindow

virtual void Component::minimisationStateChanged ( bool isNowMinimised ) [virtual]
桌面组件最小化或取消最小化时,自动调用此函数。

仅在此组件为桌面窗口的前提下才调用此函数。

参见:
getPeer, ComponentPeer::setMinimised, ComponentPeer::isMinimised
void Component::toFront ( bool shouldAlsoGainFocus )
将该组件置于同级组件的最前面。

如果其它同级组件已设置为“始终置顶”,那么此函数不能将该组件置于这些置顶组件的前面,除非该组件也设置了“始终置顶”。

参数:
shouldAlsoGainFocus 如果设置为true,将尝试为该组件分配键盘焦点。参见:grabKeyboardFocus()。
参见:
toBack, toBehind, setAlwaysOnTop
引用:CarbonViewWrapperComponent::carbonEventHandler() 。

void Component::toBack ( )
将该组件置于同级组件的最后面(改变Z-顺序)。

如果该组件已设置为“始终置顶”,此函数仅将该组件置于其它“始终置顶”组件的后面。

参见:
toFront, toBehind, setAlwaysOnTop
void Component::toBehind ( Component * other )
将该组件置于参数组件的后面(改变Z-顺序)。

参见:
toFront, toBack
void Component::setAlwaysOnTop ( bool shouldStayOnTop )
设置该组件是否始终位于同级组件的最前面。

参见:
isAlwaysOnTop
bool Component::isAlwaysOnTop ( ) const throw ()
如果该组件已设置为始终位于同级组件的最前面,则返回true

参见:
setAlwaysOnTop
int Component::getX ( ) const throw ()
返回该组件的左边缘x坐标。

返回的值为该组件距离其父级组件左边缘的像素值。

注意:如果使用了setTransform()进行缩放、旋转等“无损”变换, 那么此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件的边框。

int Component::getY ( ) const throw ()
返回该组件顶边缘的y坐标。

返回的值为该组件距离其父级组件顶边缘的像素值。

注意:如果使用了setTransform()进行缩放、旋转等“无损”变换, 那么此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件的边框。

int Component::getWidth ( ) const throw ()
返回组件的宽度(单位:像素)。

引用:CarbonViewWrapperComponent::createWindow(), LassoComponent< SelectableItemType >::paint(), CarbonViewWrapperComponent::setEmbeddedWindowToOurSize(), CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize()

int Component::getHeight ( ) const throw ()
返回组件的高度(单位:像素)。

引用: CarbonViewWrapperComponent::createWindow(), LassoComponent< SelectableItemType >::paint(), CarbonViewWrapperComponent::setEmbeddedWindowToOurSize(), CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize()

int Component::getRight ( ) const throw ()
返回该组件右边缘的x坐标。

返回的值为该组件距离其父级组件左边缘的像素值。

注意:如果使用了setTransform()进行缩放、旋转等“无损”变换, 那么此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件的边框。

const Point Component::getPosition ( ) const throw ()
返回该组件的左上角位置。返回类型为Point。

int Component::getBottom ( ) const throw ()
返回该组件底边缘的y坐标。

返回的值为该组件距离其父级组件顶边缘的像素值。

注意:如果使用了setTransform()进行缩放、旋转等“无损”变换, 那么此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件的边框。

const Rectangle& Component::getBounds ( ) const throw ()
返回此组件的边界。

返回的值为该组件相对于其父级组件左上原点的像素值。

注意:如果使用了setTransform()进行缩放、旋转等“无损”变换, 那么此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件的边框。

引用:LassoComponent< SelectableItemType >::dragLasso().

const Rectangle Component::getLocalBounds ( ) const throw ()
返回组件的边界,相对于其自身的原点。

此函数类似于getBounds(),所不同的,参照的坐标系原点为该组件自身的左上原点,即矩形返回值的起点坐标为(0, 0)。这两个函数返回的宽度和高度一样,均为组件自身的宽度和高度。

const Rectangle Component::getBoundsInParent ( ) const throw ()
返回此组件所覆盖的父级组件的区域。

返回值为相对于父级组件坐标空间的区域。如果此组件使用了无损变换(仿射变换),则返回的值为完整涵盖变换后的边框的最小区域。如果此组件没有父级组件,则与getBounds()函数返回的值相同。

void Component::getVisibleArea ( RectangleList & result,
bool includeSiblings
) const
返回此组件未被其它组件所遮盖的、且不透明的区域。

RectangleList代表所返回的未被此组件的子组件所遮盖的可视区域。

如果参数includeSiblings为true,将一并考虑覆盖此组件的同级组件。

int Component::getScreenX ( ) const
返回此组件相对于屏幕原点的X坐标。

参见:
getX, localPointToGlobal
引用:CarbonViewWrapperComponent::createWindow(), 和CarbonViewWrapperComponent::setEmbeddedWindowToOurSize().

int Component::getScreenY ( ) const
返回此组件相对于屏幕原点的Y坐标。

参见:
getY, localPointToGlobal
引用:CarbonViewWrapperComponent::createWindow(), CarbonViewWrapperComponent::setEmbeddedWindowToOurSize().

const Point Component::getScreenPosition ( ) const
返回此组件的左上角相对于屏幕左上角的位置。

参见:
getScreenBounds
const Rectangle Component::getScreenBounds ( ) const
返回此组件相对于屏幕左上角的边界。

参见:
getScreenPosition
const Point Component::getLocalPoint ( const Component * sourceComponent,
const Point< int > & pointRelativeToSourceComponent
) const
根据此组件的坐标空间转换一个坐标值(Point)。

该点的坐标相对于其它组件,返回的点则是相对于此组件的。如果参数sourceComponent为null,则参数点为全局性的屏幕坐标。

const Rectangle Component::getLocalArea ( const Component * sourceComponent,
const Rectangle< int > & areaRelativeToSourceComponent
) const
根据此组件的坐标空间转换一个矩形区域。

该矩形的坐标相对于其它组件,返回的点则是相对于此组件的。如果参数sourceComponent为null,则矩形参数为屏幕坐标。

如果已使用setTransform ()方法进行了缩放、旋转等无损变换,那么源矩形可能无法转换为实际的目标空间,这种情况下将返回完整包含整个变换区域的最小矩形。

const Point Component::localPointToGlobal ( const Point< int > & localPoint ) const
将此组件的原点转换为屏幕坐标。

参见:
getLocalPoint, localAreaToGlobal
const Rectangle Component::localAreaToGlobal ( const Rectangle< int > & localArea ) const
将此组件的矩形空间转换为屏幕坐标

如果已使用setTransform ()方法进行了缩放、旋转等无损变换,那么源矩形可能无法转换为实际的目标空间,这种情况下将返回完整包含整个变换区域的最小矩形。

参见:
getLocalPoint, localPointToGlobal
void Component::setTopLeftPosition ( int x
int y
)
将此组件移动到新的位置。

此函数改变组件的左上原点位置,不改变其大小。 左上原点为相对于其父级组件的位置。

如果此组件发生了实质上的移动,则同步调用moved()函数。

注意,如果已使用setTransform()方法进行了无损变换,则此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件所设置的边界。

参见:
setBounds, ComponentListener::componentMovedOrResized
void Component::setTopRightPosition ( int x
int y
)
将此组件移动到新的位置。

改变组件右上角的位置(不改变其大小)。该位置相对于此组件的父级组件的左上原点。

如果此组件发生了实质上的移动,则同步调用moved()函数。

注意,如果已使用setTransform()方法进行了无损变换,则此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件所设置的边界。

void Component::setSize ( int newWidth,
int newHeight
)
更改组件的大小。

更改组件大小后将同步调用resized()函数。

注意,如果已使用setTransform()方法进行了无损变换,则此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件所设置的边界。

引用:LassoComponent< SelectableItemType >::beginLasso(), and CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

void Component::setBounds ( int x
int y
int width
int height
)
改变组件的位置和大小。

x、y为相对于此组件父级组件左上原点的坐标值,如果此组件为桌面窗口,则起点坐标相对于屏幕的左上原点。

改变组件的起点坐标,将同步调用moved()函数。 改变其大小,则同步调用resized()函数。

注意,如果已使用setTransform()方法进行了无损变换,则此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件所设置的边界。

参见:
setTopLeftPosition, setSize, ComponentListener::componentMovedOrResized
引用: LassoComponent< SelectableItemType >::dragLasso().

1 Like

void Component::setBounds ( const Rectangle< int > & newBounds )
改变组件的位置和大小。

x、y为相对于此组件父级组件左上原点的坐标值,如果此组件为桌面窗口,则起点坐标相对于屏幕的左上原点。

改变组件的起点坐标,将同步调用moved()函数。改变其大小,则同步调用resized()函数。

注意,如果已使用setTransform()方法进行了无损变换,则此组件的边界将不再直接反映出它相对于父级组件的位置,无损变换将应用到此组件所设置的边界。

参见:
setBounds
void Component::setBoundsRelative ( float proportionalX,
float proportionalY,
float proportionalWidth,
float proportionalHeight
)
根据父级组件的大小和区域更改此组件的位置和大小。

参数值为父级组件的比例,比如:setBoundsRelative (0.2f, 0.2f, 0.5f, 0.5f)将设置为父级组件的一半宽度和一半高度,左上起点则是父级组件宽度和高度20%的位置。

参见:
setBounds
void Component::setBoundsInset ( const BorderSize & borders )
基于四周的空间更改此组件的位置和大小。

此函数通过指定该组件四个边界距离其父级组件四个边界的距离来定位该组件。

参见:
setBounds
void Component::setBoundsToFit ( int x
int y
int width
int height
const Justification & justification,
bool onlyReduceInSize
)
按给定的区域定位此组件,宽高比不变。

如果onlyReduceInSize为false,此组件将重新调整大小以匹配给定的区域,同时,不改变其原始宽高比。此函数不适用于大小为0的组件。如果onlyReduceInSize为true,且此组件大于给定区域时,将仅对大于部分做减小处理,这样一来,将改变此组件的原始宽高比。

justification用来设置该组件在给定区域中的定位方式(居中、靠左、靠右)等等。

参见:
setBounds
void Component::setCentrePosition ( int x
int y
)
更改此组件的中心位置。

不改变组件的大小,改变其位置。使该组件的中心点位于父级组件的某个坐标点处。

参见:
setBounds
void Component::setCentreRelative ( float x
float y
)
更改此组件的中心位置。

不改变组件的大小,使该组件的中心点位于父级组件的某个位置处。比如:setCentreRelative (0.5f, 0.5f)将使该组件在其父级组件内自动居中。

void Component::centreWithSize ( int width
int height
)
更改此组件的大小,并位于父级组件的中心。

改变大小之后,自动移动该组件,使其在父级组件内自动居中。如果此组件为桌面窗口,或者没有父级组件,那么将自动位于屏幕的居中位置。

void Component::setTransform ( const AffineTransform & transform
设置此组件的变换矩阵(无损变换。缩放、旋转等等)。

如果该组件进行了无损变换,则其位置将被扭曲或改变,这意味着传递给setBounds()的参数值将不再反映出该组件在其父级组件中的实际位置和大小,甚至,该组件有可能位于其父级组件之外而不可视。

使用无损变换时要特别注意,特别是牵扯到坐标点和区域定位时,此时应始终使用getLocalPoint()、getLocalArea()等函数来完成此事, 绝对不要在不同的组件之间进行此类操作。

目前,桌面窗口不支持无损变换,因此,对桌面窗口的无损转换将被忽略。

要移除某个组件的无损变换,将参数设置为AffineTransform::identity即可。

const AffineTransform Component::getTransform ( ) const
返回此组件当前所设置的变换矩阵(缩放,旋转等等)。

关于无损变换的更多信息,请参见:setTransform().

参见:
setTransform
bool Component::isTransformed ( ) const throw ()
如果此组件当前应用了缩放、旋转等转换,则返回true。

关于无损变换的更多信息,请参见:setTransform().

参见:
setTransform
int Component::proportionOfWidth ( float proportion ) const throw ()
返回此组件的宽度比例。

此函数相当于:getWidth() * proportion。

int Component::proportionOfHeight ( float proportion) const throw ()
返回此组件的高度比例。

此函数相当于:getHeight() * proportion。

int Component::getParentWidth ( ) const throw ()
返回此组件的父级组件的宽度。

如果该组件没有父级组件(即桌面窗口),则返回屏幕的宽度。

int Component::getParentHeight ( ) const throw ()
返回此组件的父级组件的高度。

如果该组件没有父级组件(即桌面窗口),则返回屏幕的高度。

const Rectangle Component::getParentMonitorArea ( ) const
返回包含此组件的显示器的屏幕坐标系。

如果只有一个显示器,将返回该显示器的屏幕大小(左上原点和分辨率),如果有多个显示器,将返回该组件的中心点所位于的显示器的屏幕大小。

int Component::getNumChildComponents ( ) const throw ()
返回此组件包含的子组件的个数。

参见:
getChildComponent, getIndexOfChildComponent
Component* Component::getChildComponent ( int index ) const throw ()
按索引值返回该组件所包含的某个子组件。

子组件的Z序列从0开始,排序越靠前,数字越大。位于最前面的子组件,其索引值为(getNumChildComponents() - 1)。

如果索引值超出范围,将返回一个空指针。

参见:
getNumChildComponents, getIndexOfChildComponent
int Component::getIndexOfChildComponent ( const Component * child ) const throw ()
返回此组件所包含的某个子组件的索引值。

该组件的第一个子组件将返回0,也即位于最后面的子组件。返回值越大,该子组件越靠前。

如果给定的参数并非该组件的子组件,则返回-1。

参见:
getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind
void Component::addChildComponent ( Component * child )
int zOrder = -1
)
此组件添加一个子组件。

添加子组件并不意味着该组件将自动销毁所添加的子组件。销毁所添加的子组件是程序员要负责的事。注意,要安全的销毁某个组件,无需首先从父级组件中移除之。销毁的时候,将自动移除并发送相应的消息。

如果要添加的子组件已经是当前组件的子组件,那么此函数将不起任何作用,也不改变所有子组件的Z顺序。

参数:
child 要添加的新组件。如果该组件已经是另一个组件的子组件,则首先从另一个组件中移除之。
zOrder 子组件的Z序列。值为-1将置于最前面,0为置于最后面。
参见:
removeChildComponent, addAndMakeVisible, getChild, ComponentListener::componentChildrenChanged
void Component::addAndMakeVisible ( Component * child
int zOrder = -1
)
此组件添加一个子组件,如果子组件当前不可见,则使之可见。

相当常用的函数。相当于连续使用这两个函数:子组件->setVisible (true),addChildComponent()。参见addChildComponent()以获取更多信息。

void Component::removeChildComponent ( Component * childToRemove )
移除此组件所包含的某个子组件。

如果给出的参数并非当前组件的子组件,则此函数不进行任何处理。

注意:移除一个子组件并不能销毁它!要安全的销毁某个组件,无需首先从父级组件中移除之。销毁的时候,将自动移除并发送相应的消息。

参见:
addChildComponent, ComponentListener::componentChildrenChanged
Component* Component::removeChildComponent ( int childIndexToRemove )
按索引值移除该组件所包含的某个子组件。

此函数返回要移除的子组件的指针,如果索引越界则返回null。

注意:移除一个子组件并不能销毁它!要安全的销毁某个组件,无需首先从父级组件中移除之。销毁的时候,将自动移除并发送相应的消息。

参见:
addChildComponent, ComponentListener::componentChildrenChanged
void Component::removeAllChildren ( )
移除该组件所包含的所有子组件。

注意,此函数并不能销毁子组件!要移除并销毁子组件,请使用deleteAllChildren()函数。

void Component::deleteAllChildren ( )
移除该组件所包含的所有子组件,并销毁它们。

参见:
removeAllChildren
Component* Component::getParentComponent ( ) const throw ()
返回此组件的父级组件。

如果当前组件为顶级窗口,或者没有父级组件,则返回null。

引用:LassoComponent< SelectableItemType >::beginLasso(), 和CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize()

template
TargetClass* Component::findParentComponentOfClass ( TargetClass *const dummyParameter = 0 ) const
按给定的类搜索父级组件。

比如:findParentComponentOfClass ()将返回第一个可动态转换为MyComp的父级组件,如果没有合适的父级组件,则返回0。

如果IDE使用VC6,则参数dummyParameter是必须的,否则会出现编译错误。

Component* Component::getTopLevelComponent ( ) const throw ()
返回包含该组件及其父级组件的最顶级组件。

此函数将从当前组件开始逐层搜索,直至找到没有父级组件的最顶级组件,而后返回所找到的最顶级组件。最顶级组件也许是桌面窗口,或者是没有父级组件的顶层组件。

引用:CarbonViewWrapperComponent::carbonEventHandler()

bool Component::isParentOf ( const Component * possibleChild ) const throw ()
检测该组件是否为给定组件的父级组件。

此函数递归检查当前组件的所有子组件,直至检查结束。

virtual void Component::parentHierarchyChanged ( ) [virtual]
当此组件改变所隶属的父级组件时,自动调用此函数。

当某个组件添加或移除子组件时,此函数将被该组件的所有子组件所自动调用。

派生的子类可重写此函数以实现更多的功能。

参见:
getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged
引用:Button, KeyMappingEditorComponent, WebBrowserComponent, DocumentWindow, TopLevelWindow, Drawable, DrawableComposite

virtual void Component::childrenChanged ( ) [virtual]
当此组件添加或移除子组件时,自动调用此函数。

参见:
parentHierarchyChanged
重新实现:DrawableComposite.

virtual bool Component::hitTest ( int x
int y
) [virtual]
检测给定的点是否位于此组件内。

重写此方法允许所创建的组件只拦截在设定区域中发生的鼠标点击事件。

此函数用于表明某个坐标点是否位于该组件内,并被contains()和 getComponentAt()等函数所调用,以判断鼠标点击了哪个组件。

自定义形状的组件可能需要重写此函数以执行更复杂的判断检测。

返回的真假值取决于setInterceptsMouseClicks()函数所设置的返回值(默认的返回值为true)。

注意,hit检测与该组件是否透明无关。

应用程序不应直接调用hitTest()函数,contains()函数也许是更合适的选择。因为此函数将一并检测该组件的父级组件所堵塞的区域。

另注意,桌面组件将忽略此函数。

参数:
x 要检测的x坐标,相对于该组件的左边缘。必须确保此值大于等于0,并小于组件的宽度。
y 要检测的y坐标,相对于该组件的顶边缘。必须确保此值大于等于0,并小于组件的高度。
返回值:
如果点击的位置在该组件内,则返回true。
参见:
setInterceptsMouseClicks, contains
以下类中重写此函数:ImageButton, ResizableBorderComponent, ResizableCornerComponent, TabBarButton, LassoComponent< SelectableItemType >, CallOutBox.

void Component::setInterceptsMouseClicks ( bool allowClicksOnThisComponent,
bool allowClicksOnChildComponents
) throw ()
改变hitTest()方法的参数,设置拦截鼠标点击事件。

设置为false是一种简单的方法,使一个组件能够将鼠标点击事件传递给位于其后的所有组件。

创建一个组件后,此函数的默认设置为true。

参数:
allowClicksOnThisComponent 如果为true,hitTest()将始终返回true;如果为false,将返回false,或者其子组件将返回true,前提是allowClicksOnChildComponents已设置为true。
allowClicksOnChildComponents 如果为true并且allowClicksOnThisComponent为false,那么子组件能够被正常点击,但是该组件内的点击将直接通过。如果为false并且allowClicksOnThisComponent也为false,那么此组件及其所有的子组件均无法点击。
参见:
hitTest, getInterceptsMouseClicks
void Component::getInterceptsMouseClicks ( bool allowsClicksOnThisComponent,
bool allowsClicksOnChildComponents
) const throw ()
获取鼠标点击拦截标记的当前状态。

返回setInterceptsMouseClicks()所设置的状态。

参见:
setInterceptsMouseClicks
bool Component::contains ( const Point< int > & localPoint )
如果给定的坐标点位于此组件或它的子组件之内,则返回true。

永远不要改写此函数!使用hitTest来创建自定义的点击区域。

参数:
localPoint 要检测的坐标点,相对于此组件的左上原点。
返回值:
如果该点位于此组件的点击检测区域,并且该区域未被父级组件所遮盖,则返回true。注意,此函数不考虑任何覆盖的同级组件。对于这一点,可参见:reallyContains()
参见:
hitTest, reallyContains, getComponentAt
bool Component::reallyContains ( const Point< int > & localPoint,
bool returnTrueIfWithinAChild
)
如果给定的点位于此组件之内则返回true,同时考虑到任何重叠的同级组件。

参数:
localPoint 要检测的坐标点,相对于此组件的左上原点。
returnTrueIfWithinAChild 如果检测点位于此组件的子组件之内,此参数决定是否影响返回结果。
参见:
contains, getComponentAt
Component* Component::getComponentAt ( int x
int y
)
返回给定的点所位于的组件。

参数:
x 要检测的坐标点,相对于此组件的左边缘。
y 要检测的坐标点,相对于此组件的上边缘。
返回值:
检测点所在的位置有可能是一个组件,也有可能为0,或者为某个组件的子组件。注意,此函数实际上不访问重叠的同级组件,要访问其它同级组件,则让父级组件调用此函数。
参见:
hitTest, contains, reallyContains
Component* Component::getComponentAt ( const Point< int > & position )
返回给定的点所位于的组件。

参数:
position 要检测的坐标点,相对于此组件的左上原点。
返回值:
检测点所在的位置有可能是一个组件,也有可能为0,或者为某个组件的子组件。注意,此函数实际上不访问重叠的同级组件,要访问其它同级组件,则让父级组件调用此函数。
参见:
hitTest, contains, reallyContains
void Component::repaint ( )
标记整个组件需要重绘。

调用此函数并不会立即进行重绘,而是提示操作系统需要重绘此组件。稍后,操作系统将发送重绘消息,此时才进行重绘处理。无法保证操作系统在多久之后,这取决于操作系统的消息队列。

如果已调用setBufferedToImage()函数设置了此组件的缓冲,则repaint()将使用此组件的缓冲变成无效状态。

要重绘此组件中的某个区域,而不是全部重绘,可使用:repaint (int, int, int, int)函数。

参见:
paint
void Component::repaint ( int x
int y
int width
int height
)
标记组件的某个区域需要重绘。

调用此函数并不会立即进行重绘,而是提示操作系统需要重绘此组件的某个区域。稍后,操作系统将发送重绘消息,此时才进行重绘处理。无法保证操作系统在多久之后,这取决于操作系统的消息队列。

传递的参数确定要重绘的区域。

参见:
repaint()
void Component::repaint ( const Rectangle< int > & area )
标记组件的某个区域需要重绘。

调用此函数并不会立即进行重绘,而是提示操作系统需要重绘此组件的某个区域。稍后,操作系统将发送重绘消息,此时才进行重绘处理。无法保证操作系统在多久之后,这取决于操作系统的消息队列。

传递的参数确定要重绘的区域。

参见:
repaint()
void Component::setBufferedToImage ( bool shouldBeBuffered )
设置该组件使用内部缓冲来优化重绘操作。

设置为true将导致组件分配一个内部缓冲区以绘制其本身,因此,当重绘自身时可使用该缓冲区,而不是实际调用paint ()方法。

缓冲区一直保留到该组件直接调用repaint()方法,或者直到该组件调用了resized()函数。此后,再次绘制此组件将重新使用paint()方法。

注意,仅使用paint()方法进行绘制时才使用缓冲区,子组件不使用此缓冲区,paintOverChildren()方法也不使用。

参见:
repaint, paint, createComponentSnapshot
const Image Component::createComponentSnapshot ( const Rectangle< int > & areaToGrab,
bool clipImageToComponentBounds = true
)
生成此组件某个区域的屏幕快照。

此函数将返回一个新的Image,大小为所给出的矩形区域,抓取的屏幕快照中包含所有位于该区域的子组件。

获取的图像是否具有alpha通道取决于图像是否设置了透明效果。

如果clipImageToComponentBounds参数为true,且所抓取的快照区域超过了组件的大小,将自动裁剪。如果clipImageToComponentBounds参数为false,则超出范围的部分不进行裁剪。

参见:
paintEntireComponent
void Component::paintEntireComponent ( Graphics & context
bool ignoreAlphaLevel
)
用给定的绘图环境重绘此组件及其所有的子组件。

通常情况下,程序员很少有机会使用此函数,仅在非常特殊的目的下才会使用定制的绘图环境来绘制组件所显示的内容。比如:创建此组件的快照。

此函数将调用paint()、paintOverChildren(),并递归调用其子组件的paintEntireComponent()函数。

此函数返回之后,图形环境也许将处于未定义状态,所以,下次使用之前可能需要再次定义图形环境。

如果参数ignoreAlphaLevel为false,则组件将使用getAlpha()的返回值来设置透明度。如果参数ignoreAlphaLevel为true,将忽略透明设置(alpha值为1.0F)。

void Component::setPaintingIsUnclipped ( bool shouldPaintWithoutClipping ) throw ()
此方法允许表明此组件在重绘时无需剪切图形环境。

通常情况下无需使用此设置,但如果有大量简单的组件需要渲染,并且这些组件的绘制确保不会超越其自身大小,这种情况下有可能会用到此函数。如果开启此模式,则需要确保绘制函数不被Graphics::fillAll()这样的函数所调用,并且不会进行超越组件边界的绘制,因为这样将会产生失真。

void Component::setComponentEffect ( ImageEffectFilter * newEffect )
设置组件的外观。

当组件设置了效果过滤器,那么该效果将自动被paint()方法所使用。有几个预设的效果,比如阴影或发光等等,还可以自定义。

该函数的实参不会被该组件销毁,程序员必须手动销毁该对象。

要移除已经设置的效果器,实参为空指针即可。

参见:
ImageEffectFilter, DropShadowEffect, GlowEffect
ImageEffectFilter* Component::getComponentEffect ( ) const throw ()
返回此组件当前所设置的外观效果。

参见:
setComponentEffect
LookAndFeel& Component::getLookAndFeel ( ) const throw ()
获取该组件所使用的外观及感觉(look-and-feel)。

如果该组件没有设置LAF(外观和感觉),则返回其父级组件的外观和感觉。如果此组件没有父级组件,则返回默认值。

参见:
setLookAndFeel, lookAndFeelChanged
void Component::setLookAndFeel ( LookAndFeel * newLookAndFeel )
设置此组件的外观与感觉(Look-and-Feel)。

此函数将影响到尚未设置LAF的子组件。

实参对象不会被组件销毁,程序员需手工销毁之。该对象可随时调用,直至使用它的组件被销毁。

调用此函数将一并调用sendLookAndFeelChange()函数.

参见:
getLookAndFeel, lookAndFeelChanged
virtual void Component::lookAndFeelChanged ( ) [virtual]
当该组件所使用的外观与感觉发生变化时,自动调用此函数。

当组件的外观和感觉改变时,该组件及其所有的子组件将自动调用此函数。子组件采用递归的方式调用。

此函数也可通过sendLookAndFeelChange()方法来手动触发,如果应用程序使用了LookAndFeel类,则有可能进行内部改变。

参见:
sendLookAndFeelChange, getLookAndFeel
重新实现:ComboBox, ProgressBar, Slider, FilenameComponent, ScrollBar, TabbedButtonBar, TabbedComponent, AlertWindow, DocumentWindow, ResizableWindow

void Component::sendLookAndFeelChange ( )
设置此组件和它的所有子组件调用lookAndFeelChanged()方法。

此函数将递归调用所有的下级组件的lookAndFeelChanged()函数。

参见:
lookAndFeelChanged
void Component::setOpaque ( bool shouldBeOpaque )
设置不透明。

组件始终使用纯色来绘制其内容,因而此函数将完整覆盖位于其后的所有组件的重绘事件。

此函数用来优化绘制事件,因为不透明的窗口无需额外的绘制。

默认情况下,组件是透明的,此函数使之不透明。

参见:
isOpaque, getVisibleArea
bool Component::isOpaque ( ) const throw ()
如果此组件为不透明的(无任何透明的区域),则返回true。

返回值:
返回setOpaque()函数所设置的值。默认为false。
参见:
setOpaque
void Component::setBroughtToFrontOnMouseClick ( bool shouldBeBroughtToFront ) throw ()
设置当鼠标点击时,此组件是否自动切换到最前面。

设置为true,则鼠标在此组件及其子组件的区域内点击时,此组件自动置于最前面。

注意,顶级窗口是否置于最前面将取决于操作系统。

默认设置为false。

参见:
setMouseClickGrabsKeyboardFocus
bool Component::isBroughtToFrontOnMouseClick ( ) const throw ()
如果鼠标点击时此组件自动切换到最前面,则返回true。

参见:
setBroughtToFrontOnMouseClick
void Component::setWantsKeyboardFocus ( bool wantsFocus ) throw ()
设置一个标志,以表明此组件是否需要键盘焦点。

默认情况下,组件对是否拥有键盘焦点不感兴趣,此方法使组件开启该项属性。

参见grabKeyboardFocus()方法获取使组件拥有焦点的更多信息。

参见:
grabKeyboardFocus, getWantsKeyboardFocus
bool Component::getWantsKeyboardFocus ( ) const throw ()
如果此组件对键盘焦点感兴趣,则返回true。

返回由setWantsKeyboardFocus()方法所设置的值。 默认为false。

参见:
setWantsKeyboardFocus
void Component::setMouseClickGrabsKeyboardFocus ( bool shouldGrabFocus )
设置点击此组件时是否拥有键盘焦点。

默认设置为true,但可以使用该函数改变这一点,即:即使用户点击某个组件,也不使其拥有焦点。

bool Component::getMouseClickGrabsKeyboardFocus ( ) const throw ()
返回setMouseClickGrabsKeyboardFocus()所设置的值。

参见:setMouseClickGrabsKeyboardFocus()以获得更多信息。

void Component::grabKeyboardFocus ( )
试图使此组件拥有键盘焦点。

点击某个组件或者该组件调用grabKeyboardFocus()函数之后,以下处理判断哪个组件应获得焦点:

如果该组件被设置为鼠标点击以获得焦点,比如调用getWantsKeyboardFocus函数,则自动拥有焦点。
如果组件本身不希望拥有焦点,则焦点自动转移给该组件的子组件,类似于KeyboardFocusTraverser::getDefaultComponent()函数的作用。
如果该组件的所有子组件同样不想拥有焦点,则焦点转移给该组件的父级组件,直至没有父级组件的顶级组件,这种情况下,顶级组件将自动拥有焦点。
参见:
setWantsKeyboardFocus, getWantsKeyboardFocus, hasKeyboardFocus, getCurrentlyFocusedComponent, focusGained, focusLost, keyPressed, keyStateChanged

1 Like

bool Component::hasKeyboardFocus ( bool trueIfChildIsFocused ) const
如果此组件当前拥有键盘焦点则返回true。

参数:
trueIfChildIsFocused 如果为true, 且该组件或者其所有的子组件拥有焦点时,此函数均返回true。如果为false,则仅当该组件实际拥有焦点时才返回true。
参见:
grabKeyboardFocus, setWantsKeyboardFocus, getCurrentlyFocusedComponent, focusGained, focusLost
static Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent ( ) throw () [static]
返回当前拥有键盘焦点的某个组件。

返回值:
拥有焦点的组件,如果没有组件拥有焦点,则返回null。
void Component::moveKeyboardFocusToSibling ( bool moveToNext )
尝试将键盘焦点转移给下一个同级组件。

此方法将尝试把焦点转移给上一个或下一个组件。使用TAB键转移焦点时,将自动调用此函数。

getWantsKeyboardFocus()返回值为false的组件将不予考虑。

参数:
moveToNext 如果为true,则焦点向前转移;如果为false,则焦点向后转移。
参见:
grabKeyboardFocus, setFocusContainer, setWantsKeyboardFocus
virtual KeyboardFocusTraverser* Component::createFocusTraverser ( ) [virtual]
创建一个KeyboardFocusTraverser对象以确定此组件传递焦点的逻辑。

默认情况下,如果此组件为setFocusContainer()方法所设置的焦点容器,则返回KeyboardFocusTraverser的默认值。如果组件不是焦点容器,则返回其父级组件的KeyboardFocusTraverser。

如果重写此函数以返回定制的KeyboardFocusTraverser,那么此组件及其所有的子组件将使用新对象来确定拥有焦点方式。

此函数应返回一个新对象,当不再需要时,由程序员负责销毁之。

重新实现:Label

int Component::getExplicitFocusOrder ( ) const
返回此组件的焦点顺序,如果已指定。

默认情况下,组件没有焦点顺序,此时将返回0。返回的值越小,则此组件的焦点顺序越靠前。

使用setExplicitFocusOrder()函数可改变焦点顺序。

焦点顺序也许被KeyboardFocusTraverser类所使用,作为算法的一部分以决定组件转移焦点的顺序。参见KeyboardFocusTraverser类以获取更多信息。

参见:
moveKeyboardFocusToSibling, createFocusTraverser, KeyboardFocusTraverser
void Component::setExplicitFocusOrder ( int newFocusOrderIndex )
按索引值设置焦点转移的顺序。

小于等于0的值表明不显式设置焦点顺序,焦点转移将使用其它因数,比如组件的位置等等。

参见:
getExplicitFocusOrder, moveKeyboardFocusToSibling
void Component::setFocusContainer ( bool shouldBeFocusContainer ) throw ()
设置此组件是否为焦点容器。

此函数被默认被createFocusTraverser()所调用,以查找第一个拥有焦点且有意成为焦点容器的父级组件。

因此,参数设置为true将导致此组件作为顶级焦点容器组件。

参见:
isFocusContainer, createFocusTraverser, moveKeyboardFocusToSibling
bool Component::isFocusContainer ( ) const throw ()
如果此组件为焦点容器,则返回true。

参见:setFocusContainer()

参见:
setFocusContainer, moveKeyboardFocusToSibling, createFocusTraverser
bool Component::isEnabled ( ) const throw ()
如果此组件及其所有的子组件为开启状态,则返回true。

默认情况下,组件为开启状态,可使用setEnabled()函数禁用或开启。 如何设置,取决于组件的类型和程序员的目的。比如:按钮和滑块在开启或禁用状态下,将显示截然不同的外观。

注意,如果该组件的上级组件之一设置为禁用状态,则此函数将始终返回false,即使此组件自身的状态为开启。

参见:
setEnabled, enablementChanged
void Component::setEnabled ( bool shouldBeEnabled )
启用或禁用此组件。

禁用某个组件将导致该组件的所有子组件处于禁用状态。

同样,即使开启某个已禁用的组件的子组件,也不会产生任何作用,直至子组件的父组件也处于开启状态。

参见:
isEnabled, enablementChanged
virtual void Component::enablementChanged ( ) [virtual]
启用或禁用此组件时自动调用此函数。

此组件的某个上级组件改变开启或禁用状态时将触发此函数,同时也将影响到该组件的状态。

默认情况下,此函数不起任何作用,但派生类如果需要重绘自身或利用状态改变之际做某事,则可以重写此函数。

参见:
setEnabled, isEnabled
重新实现:Button, ToolbarButton, ComboBox, Label, Slider, TextEditor, TreeView, GroupComponent, PropertyComponent

void Component::setAlpha ( float newAlpha )
更改此组件的透明度。

进行绘制操作时可使用此函数,以设置透明度。0为完全透明(不可视),1.0F为完全不透明(正常状态)。

参见:
getAlpha
float Component::getAlpha ( ) const
返回此组件当前所设置的透明度。

参见:setAlpha()

void Component::setMouseCursor ( const MouseCursor & cursorType )
设置鼠标指针的外观(当鼠标指向该组件时)。

注意,此函数所设置的鼠标指针能够被getMouseCursor方法重写。

参见:
MouseCursor
virtual const MouseCursor Component::getMouseCursor ( ) [virtual]
获取当前设置的鼠标指针外观(当鼠标指向该组件时)。

默认返回由setCursor()所设置的鼠标指针,可重写此函数以实现更多的目的,比如,根据鼠标位置返回不同的指针。

参见:
MouseCursor
重新实现:TableHeaderComponent

void Component::updateMouseCursor ( ) const
强制刷新当前的鼠标指针。

如果重写了getMouseCursor()函数以控制所显示的指针,那么每次移动鼠标时均自动调用此函数。如果打算强制更新鼠标指针,而无论鼠标是否移动,则在代码中的必要位置显式调用此函数。

如果使用setMouseCursor()函数改变了鼠标指针,则无需调用此函数。

virtual void Component::paint ( Graphics & g ) [virtual]
重写此方法以绘制此组件的内容。

当组件的某个区域需要绘制、调用组件的repaint()方法,或者由于某些原因操作系统需要重新显示或刷新组件内容时,均自动调用此函数。

同时,该组件的所有子组件也一并调用各自的同名方法来绘制自身。如果要绘制置于组件之前的子组件,可使用paintOverChildren()方法来完成。

如果要显式绘制组件,则使用repaint()方法,此时将异步调用本函数,在稍后的某个时间,执行绘制处理。Juce类库和大多数目前流行的UI框架库一样,程序员均无法进行任何同步绘制处理。即:绘制总是异步进行的。执行的时间取决于操作系统的消息队列。

程序员也许永远无需直接调用此函数,要获取组件的快照,可使用createComponentSnapshot()或paintEntireComponent()方法。

参数:
g 图形环境,执行绘制操作所必须的参数。
参见:
repaint, paintOverChildren, Graphics
重新定义:GenericAudioProcessorEditor, Button, CodeEditorComponent, ComboBox, Label, ListBox, ProgressBar, Slider, TableHeaderComponent, TextEditor, Toolbar, TreeView, FileSearchPathListComponent, ImagePreviewComponent, GroupComponent, MultiDocumentPanel, ResizableBorderComponent, ResizableCornerComponent, ScrollBar, StretchableLayoutResizerBar, TabbedComponent, MenuBarComponent, LassoComponent< SelectableItemType >, BooleanPropertyComponent, PropertyComponent, PropertyPanel, ActiveXControlComponent, BubbleComponent, MidiKeyboardComponent, NSViewComponent, OpenGLComponent, PreferencesPanel, SystemTrayIconComponent, WebBrowserComponent, AlertWindow, CallOutBox, DocumentWindow, ResizableWindow, SplashScreen, DrawableImage, DrawableShape, DrawableText.

virtual void Component::paintOverChildren ( Graphics & g ) [virtual]
可重写此方法以绘制位于最前面的子组件。

大多数绘制操作最好使用正常的paint()方法,但如果需要绘制置于最前面的子组件,则可调用此函数。

参见:
paint, Graphics
重新实现:ListBox, TextEditor, FilenameComponent

virtual void Component::mouseMove ( const MouseEvent & e ) [virtual]
当鼠标在此组件中移动时,自动调用此函数。

如果鼠标的某个键尚未按下并且正指向当前组件,则自动调用此函数。

在调用此函数之前,组件将始终回调mouseEnter()函数。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseEnter, mouseExit, mouseDrag, contains
改写自:MouseListener

重新实现:ListBox, TableHeaderComponent, ResizableBorderComponent, MenuBarComponent, MidiKeyboardComponent

virtual void Component::mouseEnter ( const MouseEvent & e ) [virtual]
当鼠标进入此组件时,自动调用此函数。

如果鼠标的某个键尚未按下并且正进入当前组件,则自动调用此函数。

当鼠标按住某个键进出一个组件时,并不产生mouseEnter或mouseExit事件,仅发送鼠标首次按下时产生的mouseDrag消息,鼠标拖拽的消息发送给此组件,直至松开按键。

如果写了一个组件类或该类的派生类,在鼠标指针进入或退出时需要重绘自身,使用此函数也许更方便:setRepaintsOnMouseActivity()。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseExit, mouseDrag, mouseMove, contains
改写自:MouseListener

重新实现:Button, TableHeaderComponent, ResizableBorderComponent, MenuBarComponent, MidiKeyboardComponent

virtual void Component::mouseExit ( const MouseEvent & e ) [virtual]
当鼠标指针退出此组件时,自动调用此函数。

当鼠标指针移动到组件的边界之外时调用此函数。

如果按住鼠标某个键进行拖拽操作,在离开组件的边界并释放鼠标按键后,将调用此函数,之后再调用mouseUp()函数。

如果写了一个组件类或该类的派生类,在鼠标指针进入或退出时需要重绘自身,使用此函数也许更方便:setRepaintsOnMouseActivity()。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseEnter, mouseDrag, mouseMove, contains
改写自:MouseListener

重新实现:Button, ListBox, TableHeaderComponent, MenuBarComponent, MidiKeyboardComponent

virtual void Component::mouseDown ( const MouseEvent & e ) [virtual]
当鼠标指针位于此组件并且点击某个鼠标键,尚未释放时,自动调用此函数。

参数为MouseEvent类的对象,包含大量的方法以判断哪个鼠标键被按下、同时还按下了哪个功能键,比如Shift键、Ctrl键等等。

一旦按下了某个鼠标键并移动鼠标时,将调用mouseDrag方法,直至松开按键。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseUp, mouseDrag, mouseDoubleClick, contains
改写自:MouseListener

重新实现:Button, CodeEditorComponent, ComboBox, Slider, TableHeaderComponent, TextEditor, Toolbar, ResizableBorderComponent, ResizableCornerComponent, ScrollBar, StretchableLayoutResizerBar, MenuBarComponent, MidiKeyboardComponent, AlertWindow, ResizableWindow

virtual void Component::mouseDrag ( const MouseEvent & e ) [virtual]
当鼠标拖拽时,自动调用此函数。

当鼠标指针位于组件内并按下某个鼠标键后,则每次移动鼠标,组件将收到mouseDrag回调消息,即使鼠标指针位于边界之外也依然如此。

如果打算执行某些离开组件边界的拖拽处理,并且组件产生滚屏效果,函数beginDragAutoRepeat()也许更有用。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseUp, mouseMove, contains, beginDragAutoRepeat
改写自:MouseListener

重新实现:Button, CodeEditorComponent, ComboBox, Slider, TableHeaderComponent, TextEditor, ResizableBorderComponent, ResizableCornerComponent, ScrollBar, StretchableLayoutResizerBar, MenuBarComponent, MidiKeyboardComponent, AlertWindow, ResizableWindow

virtual void Component::mouseUp ( const MouseEvent & e ) [virtual]
鼠标点击并释放某个鼠标按键时自动调用此函数。

mouseUp回调将发送给此组件,即使当释放鼠标按键时它实际上正指向不同的组件。

MouseEvent对象包含大量的鼠标按键信息以判断哪个鼠标键被按下了。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseDrag, mouseDoubleClick, contains
改写自:MouseListener

重新实现:Button, CodeEditorComponent, ComboBox, Label, ListBox, Slider, TableHeaderComponent, TextEditor, ResizableBorderComponent, ResizableCornerComponent, ScrollBar, MenuBarComponent, MidiKeyboardComponent

virtual void Component::mouseDoubleClick ( const MouseEvent & e ) [virtual]
鼠标在此组件中双击时自动调用此函数。

参数为MouseEvent类的对象,包含大量的方法以判断哪个鼠标键被按下、同时还按下了哪个功能键,比如Shift键、Ctrl键等等。

要改变两次点击的时间限定,则参见:MouseEvent::setDoubleClickTimeout。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseUp, MouseEvent::setDoubleClickTimeout, MouseEvent::getDoubleClickTimeout
改写自:MouseListener

重新实现:CodeEditorComponent, Label, Slider, TextEditor, DocumentWindow

virtual void Component::mouseWheelMove ( const MouseEvent & e,
float wheelIncrementX,
float wheelIncrementY
) [virtual]
转动鼠标滚轮键时自动调用此函数。

当鼠标指针指向该组件并转动滚动键时,此自动调用此函数。

如果不重写,该组件将把消息转发给父级组件,由父级组件收集子组件不感兴趣的鼠标滚轮消息。

参数:
e 关于鼠标指针的位置和状态的详细信息。
wheelIncrementX 水平滚动的速率和方向,正数代表向右滚动,负数代表向左滚动。
wheelIncrementY 垂直滚动的速率和方向,正数代表向上滚动,负数代表向下滚动。
改写自:MouseListener

重新实现:CodeEditorComponent, ListBox, Slider, TextEditor, ScrollBar, Viewport, MidiKeyboardComponent

static void Component::beginDragAutoRepeat ( int millisecondsBetweenCallbacks ) [static]
确保鼠标拖拽时所产生的事件数据流无停滞。

此函数将确保mouseDrag()事件能够连续发送,即使鼠标处于不移动的状态。当鼠标靠近边界时,对于具有自动卷屏性质的组件,此函数比较有用。

在mouseDown()或mouseDrag()期间,调用此函数,指定鼠标拖拽消息的最小间隔。此函数将不间断的调用,直到松开鼠标按键,此时,间隔时间自动重置。每次开始拖拽鼠标时要确保调用此函数。参数值小于等于0将取消自动重复。

参见:
mouseDrag, Desktop::beginDragAutoRepeat
void Component::setRepaintsOnMouseActivity ( bool shouldRepaint ) throw ()
鼠标指针进入或退出此组件时,自动重绘。

如果开启,则鼠标进入、退出此组件,或者在此组件内按下某个鼠标键、释放鼠标键时,将触发重绘。

此函数在鼠标指向按钮等控件时,对控件进行自我重绘时比较有用,可以避免覆盖所有不同的鼠标回调,并调用repaint()。

参见:
mouseEnter, mouseExit, mouseDown, mouseUp
void Component::addMouseListener ( MouseListener * newListener,
bool wantsEventsForAllNestedChildComponents
)
绑定鼠标事件捕获器。

如果需要获取组件内的鼠标事件,并且不打算或无法改写此函数,可为该组件附加任意数量的捕获器。这些额外的事件将被组件自身所自动调用。

注意,MouseListener同样能够附加到多个组件。

参数:
newListener 要注册的捕获器。
wantsEventsForAllNestedChildComponents 如果为true,捕获器将接收此组件及其所有子组件的回调事件,包括深层次嵌套的子组件。如果为false,则仅接收此组件的鼠标事件。
参见:
MouseListener, removeMouseListener
void Component::removeMouseListener ( MouseListener * listenerToRemove )
移除已经绑定的鼠标事件捕获器。

参见:
addMouseListener, MouseListener
void Component::addKeyListener ( KeyListener * newListener )
添加此组件能够接收的按键事件捕获器。

此组件已注册的捕获器被keyPressed()或keyStateChanged()所调用,前提是这两个函数未被改写为执行其它功能。

如果添加一个捕获器对象,要注意销毁该对象之前先移除之。

参见:
keyPressed, keyStateChanged, removeKeyListener
void Component::removeKeyListener ( KeyListener * listenerToRemove )
移除已经绑定的按键捕获器。

参见:
addKeyListener
virtual bool Component::keyPressed ( const KeyPress & key) [virtual]
当按下某个键时,自动调用此函数。

按下某个键时,拥有键盘焦点的组件将自动此函数。可使用setWantsKeyboardFocus()方法使组件拥有焦点。

如果该函数返回true,则按键事件将被该函数处理,而不再传递给其它捕获器。如果返回false,则按键将传递给该组件已注册的任意KeyListeners。尽量返回true,处理将自动停止,但是如果所有的返回均为false,事件将传递给此组件的父级组件,依此类推。

默认情况下,此函数不执行任何处理,并返回false。

参见:
keyStateChanged, getCurrentlyFocusedComponent, addKeyListener
Reimplemented in Button, CodeEditorComponent, ComboBox, ListBox, TextEditor, TreeView, FileBrowserComponent, ScrollBar, Viewport, MenuBarComponent, AlertWindow, and CallOutBox.

virtual bool Component::keyStateChanged ( bool isKeyDown ) [virtual]
当按下或释放某个键时自动调用此函数。

每次按下或松开某个键盘键时,包括Shift、Ctrl等功能键,当前拥有键盘焦点的组件将自动调用此函数。可使用setWantsKeyboardFocus()方法使组件拥有焦点。

如果该函数返回true,则按键事件将被该函数处理,而不再传递给其它捕获器。如果返回false,则该组件已经注册的KeyListeners将调用keyStateChanged函数。尽量返回true,处理将自动停止,但是如果所有的返回均为false,事件将传递给此组件的父级组件,依此类推。

默认情况下,此函数不执行任何处理,并返回false。

要获取任意时刻按下或松开的某个键,参见:KeyPress::isKeyCurrentlyDown()函数。

参数:
isKeyDown true为按下某个键,false为松开某个键。
参见:
keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener
重新实现:ComboBox, ListBox, TextEditor, MidiKeyboardComponent

virtual void Component::modifierKeysChanged ( const ModifierKeys & modifiers) [virtual]
按下或释放某个功能键时自动调用此函数。

每当按下或松开Shift、Ctrl、Alt、Command键时,当前拥有键盘焦点的组件将自动调用此函数。可使用setWantsKeyboardFocus()方法使组件拥有焦点。

默认调用父级组件的modifierKeysChanged方法,这种情况下,对按键不感兴趣的组件将给予其父级组件一个处理按键事件的机会。

参见:
keyStateChanged, ModifierKeys
重新实现Slider

virtual void Component::focusGained ( FocusChangeType cause ) [virtual]
此组件拥有键盘焦点时自动此函数。

参见:
focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
重新实现:Button, CodeEditorComponent, ComboBox, Label, TextEditor

virtual void Component::focusLost ( FocusChangeType cause ) [virtual]
此组件失去键盘焦点时自动此函数。

参见:
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
重新实现:Button, CodeEditorComponent, ComboBox, TextEditor, MidiKeyboardComponent

virtual void Component::focusOfChildComponentChanged ( FocusChangeType cause ) [virtual]
此组件的子组件拥有或失去键盘焦点时自动调用此函数。

实质上,返回值为hasKeyboardFocus (true)改变后的结果。当子组件的焦点转移时,调用此函数。

参见:
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
重新实现:Slider, TopLevelWindow

bool Component::isMouseOver ( bool includeChildren = false ) const
如果鼠标指针位于此组件则返回true。

如果鼠标未指向此组件,将返回false,即使当前正在拖拽鼠标。因此,可在mouseDrag中调用此函数以找到鼠标是否位于此组件中。

注意,当按下鼠标时,仅按下时鼠标所位于的组件返回true。

参数includeChildren为true,则鼠标位于此组件的子组件时也将返回true。

参见:
isMouseButtonDown. isMouseOverOrDragging, mouseDrag
bool Component::isMouseButtonDown ( ) const throw ()
如果正按下鼠标的某个键,则返回true。

注意,此函数相当于一个检测,以判断鼠标是否在此组件中点击了。如果A组件调用此函数,而当前鼠标正拖拽到B组件,则返回false。

参见:
isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging
bool Component::isMouseOverOrDragging ( ) const throw ()
如果鼠标指针位于此组件,或者正在此组件中拖拽,则返回true。

此函数相当于:(isMouseOver() || isMouseButtonDown())。

参见:
isMouseOver, isMouseButtonDown, isMouseButtonDownAnywhere
static bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere ( ) throw () [static]
如果正按下鼠标的某个键,则返回true。

此函数不同于isMouseButtonDown,它的作用是检测鼠标按键的当前状态。

参见:
isMouseButtonDown, ModifierKeys
引用:LassoComponent< SelectableItemType >::paint()

const Point Component::getMouseXYRelative ( ) const
返回鼠标指针相对于此组件的原点的当前位置。

返回值以组件的左上原点作为参照。

virtual void Component::resized ( ) [virtual]
此组件的大小发生变化时自动调用此函数。

当组件的大小发生变化时,通常利用该函数来重新定位其子组件。

此函数被setBounds或setSize函数所同步调用,因此重复改变组件的大小将不断调用resized方法。这一点与repaint截然不同,多次调用repaint只能在稍后某一时刻进行集中重绘。

如果当前组件为桌面顶级窗口,其大小由操作系统控制,程序所设置的大小也许将不起作用。

参见:
moved, setSize
重新实现:PluginListComponent, GenericAudioProcessorEditor, DrawableButton, ToolbarButton, CodeEditorComponent, ComboBox, Label, ListBox, Slider, TableHeaderComponent, TableListBox, TextEditor, Toolbar, ToolbarItemComponent, ToolbarItemPalette, TreeView, FileBrowserComponent, FilenameComponent, FileSearchPathListComponent, KeyMappingEditorComponent, MultiDocumentPanel, ScrollBar, TabbedButtonBar, TabbedComponent, Viewport, MenuBarComponent, PropertyComponent, PropertyPanel, AudioDeviceSelectorComponent, MidiKeyboardComponent, PreferencesPanel, WebBrowserComponent, CallOutBox, DialogWindow, DocumentWindow, ResizableWindow

virtual void Component::moved ( ) [virtual]
此组件的位置发生变化时自动调用此函数。

当该组件相对于其父级组件的位置发生变化时将自动调用此函数,而不是它在屏幕绝对位置发生改变时。因此,当父级组件移动时,该组件的所有子组件将不会调用此函数。

此函数将被setBounds、setTopLeftPosition等函数同步调用,类似于resized()方法,每次调用上述函数均自动调用本函数。

如果当前组件为桌面顶级窗口,其位置由操作系统控制,程序所设置的大小也许将不起作用。

参见:
resized, setBounds
重新实现:CallOutBox, ResizableWindow

virtual void Component::childBoundsChanged ( Component * child ) [virtual]
当此组件的某个子组件的大小和位置发生变化时,自动调用此函数。

如果父级组件要获悉它的直接子组件的变化,则重写此函数。

参见:
moved, resized, parentSizeChanged
重新实现:AudioDeviceSelectorComponent, MagnifierComponent, CallOutBox, ResizableWindow, DrawableComposite

virtual void Component::parentSizeChanged ( ) [virtual]
当此组件的上一级父组件的大小发生变化时,自动调用此函数。

如果组件为顶级窗口,此函数将表明屏幕分辨率的变化。

参见:
childBoundsChanged, moved, resized
重新实现:ResizableWindow

virtual void Component::broughtToFront ( ) [virtual]
当此组件位于其同级组件的最前面时,自动调用此函数。

组件也许已被toFront()函数或操作系统置于前面(如果是顶级窗口)。

参见:
toFront
重新实现:MultiDocumentPanelWindow

void Component::addComponentListener ( ComponentListener * newListener )
添加一个捕获器以告知组件的隶属关系或位置发生变化。

当组件的大小、位置或子组件发生变化时,将自动调用Component捕获器。参见:ComponentListener类以获取更多信息。

参数:
newListener 要注册的捕获器,如果已经注册,则此函数将不起作用。
参见:
ComponentListener, removeComponentListener
void Component::removeComponentListener ( ComponentListener * listenerToRemove )
移除已经添加的组件捕获器。

参见:
addComponentListener
void Component::postCommandMessage ( int commandId )
将某个消息发送给此组件。

此函数为一个快速而简单的方法,采用异步回调的方式将消息发送给当前组件。此函数是安全的,如果接收消息的组件是空指针或野指针,将不会出现错误。

命令ID为操作系统消息队列中要处理的handleCommandMessage()事件。

参见:
handleCommandMessage
virtual void Component::handleCommandMessage ( int commandId ) [virtual]
处理postCommandMessage()发送过来的消息。

当命令消息到达时,消息线程自动调用此函数,组件类可重写此函数以所需的方式进行处理。

参见:
postCommandMessage
重新实现:Button, TextEditor, MenuBarComponent, CallOutBox

int Component::runModalLoop ( )
进入模态(无限循环、自动置顶状态),直到循环终止。

此函数将首先使组件可见,将其置于最前面,并给予其键盘焦点。

然后,进入无限循环状态,从操作系统消息队列中调度消息,并阻碍所有其它组件的鼠标、键盘事件。

循环直至组件调用exitModalState()方法为止,或者销毁此组件为止。而后,此函数返回,返回值传递给exitModalState()函数。

参见:
enterModalState, exitModalState, isCurrentlyModal, getCurrentlyModalComponent, isCurrentlyBlockedByAnotherModalComponent, ModalComponentManager
void Component::enterModalState ( bool takeKeyboardFocus = true,
ModalComponentManager::Callback * callback = 0
)
使此组件进入模态。

组件进入模态,其它组件将无法捕获并处理鼠标和键盘事件。但是,此函数不同于runModalLoop(),因为它并不返回值。

如果takeKeyboardFocus为true,组件将使用grabKeyboardFocus()方法强制获取键盘焦点。如果为false,则保留当前的焦点位置。

参数callback可选,当组件退出模态时是否回调此函数。比如隐藏组件或调用exitModalState()函数。如果此处传递了一个对象参数,在回调之后,系统将小心的销毁该对象。

参见:
exitModalState, runModalLoop, ModalComponentManager::attachCallback
void Component::exitModalState ( int returnValue )
结束模态。

如果组件当前处于模态,此函数将使之处于非模态,并返回一个值给也许正处于模态的runModalLoop()方法。

参见:
runModalLoop, enterModalState, isCurrentlyModal
bool Component::isCurrentlyModal ( ) const throw ()
如果此组件当前为模态则返回true。

如果当前有多个模态组件,比如一个模态对话框中打开另一个模态对话框,此函数仅判断最顶层的组件是否模态。

参见:
getCurrentlyModalComponent
static int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents ( ) throw () [static]
返回当前处于模态的组件个数。

参见:
getCurrentlyModalComponent
static Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent ( int index = 0 ) throw () [static]
返回当前处于模态的组件。

指定的索引为所要返回的可能是模态的组件。模态组件列表中,每个模态组件均有一个索引值。索引为0的组件始终是当前位于最前面的组件。

返回值:
模态组件,如果当前没有模态组件,或者索引越界则返回null。
参见:
getNumCurrentlyModalComponents, runModalLoop, isCurrentlyModal
bool Component::isCurrentlyBlockedByAnotherModalComponent ( ) const
检测是否正有一个模态组件阻碍了此组件接收消息。

如果有一个模态组件,它的canModalEventBeSentToComponent()方法将被调用,以判断是否允许当前组件接收事件。

参见:
runModalLoop, getCurrentlyModalComponent
virtual bool Component::canModalEventBeSentToComponent ( const Component * targetComponent ) [virtual]
当组件为模态时,此函数允许给定组件依然可以接收消息。

当激活一个模态组件并且鼠标点击一个非模态组件时,模态组件将自动调用此函数。如果返回true,产生的事件将允许发送给目标组件。如果返回false,将阻塞所产生的事件,并回调inputAttemptWhenModal() 函数。

此函数将被isCurrentlyBlockedByAnotherModalComponent()方法所调用。默认在所有情况下均返回false。

virtual void Component::inputAttemptWhenModal ( ) [virtual]
在当前正有一个模态组件的前提下,如果尝试点击此组件,则自动调用此函数。

当某个组件处于模态并且鼠标点击另一个组件时,模态组件将收到此回调函数。

默认情况下,此函数会发出一个警示音,并将模态组件置于最前面,重写此函数可实现其它目的。

参见:
isCurrentlyBlockedByAnotherModalComponent, canModalEventBeSentToComponent
重新实现:Label, CallOutBox

NamedValueSet& Component::getProperties ( ) throw ()
获取此组件的属性设置。

每个组件都有一个NamedValueSet对象,可为该对象追加任意数据。

const NamedValueSet& Component::getProperties ( ) const throw ()
获取此组件的属性设置。

每个组件都有一个NamedValueSet对象,可为该对象追加任意数据。

const Colour Component::findColour ( int colourId,
bool inheritFromParent = false
) const
查找已经注册使用的某个颜色。

如果已经使用setColour()设置了某个颜色的ID,此函数将返回设置值。如果尚未设置颜色,此函数将尝试调用LookAndFeel类的findColour()函数。如果外观和感觉(LAF)尚未注册该颜色,则返回黑色。

各种各样的颜色以ID的形式存储于颜色枚举中,可参见Slider::ColourIds、Label::ColourIds、TextEditor::ColourIds, TreeView::ColourIds等控件的颜色枚举。

参见:
setColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
引用:LassoComponent< SelectableItemType >::paint()

void Component::setColour ( int colourId,
const Colour & colour
)
注册一个要使用的颜色。

更改颜色将导致同步回调colourChanged()函数,当组件所需的颜色变化时,可重写该函数以实现更多的目的。

关于颜色ID的更多的信息,参见findColour()。

参见:
findColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
void Component::removeColour ( int colourId )
如果某个颜色是setColour()所设置的,则移除之。

此函数将重置为默认颜色。

bool Component::isColourSpecified ( int colourId ) const
如果给定的颜色由setColour()所设置,则返回true。

void Component::copyAllExplicitColoursTo ( Component * target) const
将此组件已经注册的颜色复制给其它组件。

virtual void Component::colourChanged ( ) [virtual]
当setColour()函数改变某个颜色时,自动调用此函数。

参见:
setColour, findColour
重新实现:HyperlinkButton, TextButton, ToggleButton, ComboBox, Label, ListBox, ProgressBar, Slider, TextEditor, TreeView, GroupComponent, MidiKeyboardComponent

void* Component::getWindowHandle ( ) const
返回此组件潜在的本地窗口句柄。

此函数将依赖特定的操作系统,非高级程序员不建议使用。

引用:CarbonViewWrapperComponent::createWindow().

定义该类的头文件:
juce_Component.h

1 Like

****************** Component class END ****************************

1 Like

[size=200]LookAndFeel 外观和感觉类[/size]

LookAndFeel对象用来定义所有JUCE控件的外观,其派生类可实现应用程序的“换肤”功能。更多…

继承给:OldSchoolLookAndFeel

所有成员

public成员函数

LookAndFeel ()
创建默认的JUCE外观和感觉。

virtual ~LookAndFeel ()
析构函数。
const Colour findColour (int colourId) const throw ()
查找已经注册使用的某个颜色。
void setColour (int colourId, const Colour &colour) throw ()
注册一个要使用的颜色。
bool isColourSpecified (int colourId) const throw ()
如果给定的颜色由setColour()所设置,则返回true。
virtual const Typeface::Ptr getTypefaceForFont (const Font &font)
void setDefaultSansSerifTypefaceName (const String &newName)
允许您更改默认的sans-serif字体。
virtual const MouseCursor getMouseCursorFor (Component &component)
重写此函数可使用自定义的鼠标指针。
virtual void drawButtonBackground (Graphics &g, Button &button, const Colour &backgroundColour, bool isMouseOverButton, bool isButtonDown)
绘制一个具有菱形背景的标准按钮,
virtual const Font getFontForTextButton (TextButton &button)
virtual void drawButtonText (Graphics &g, TextButton &button, bool isMouseOverButton, bool isButtonDown)
绘制TextButton所显示的文本。
virtual void drawToggleButton (Graphics &g, ToggleButton &button, bool isMouseOverButton, bool isButtonDown)
绘制标准ToggleButton的内容。
virtual void changeToggleButtonWidthToFitText (ToggleButton &button)
virtual void drawTickBox (Graphics &g, Component &component, float x, float y, float w, float h, bool ticked, bool isEnabled, bool isMouseOverButton, bool isButtonDown)
virtual AlertWindow * createAlertWindow (const String &title, const String &message, const String &button1, const String &button2, const String &button3, AlertWindow::AlertIconType iconType, int numButtons, Component *associatedComponent)
virtual void drawAlertBox (Graphics &g, AlertWindow &alert, const Rectangle< int > &textArea, TextLayout &textLayout)
virtual int getAlertBoxWindowFlags ()
virtual int getAlertWindowButtonHeight ()
virtual const Font getAlertWindowFont ()
virtual void drawProgressBar (Graphics &g, ProgressBar &progressBar, int width, int height, double progress, const String &textToShow)
绘制进度条。
virtual void drawSpinningWaitAnimation (Graphics &g, const Colour &colour, int x, int y, int w, int h)
virtual void drawScrollbarButton (Graphics &g, ScrollBar &scrollbar, int width, int height, int buttonDirection, bool isScrollbarVertical, bool isMouseOverButton, bool isButtonDown)
绘制滚动条上的按钮。
virtual void drawScrollbar (Graphics &g, ScrollBar &scrollbar, int x, int y, int width, int height, bool isScrollbarVertical, int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown)
绘制滚动条的滑块。
virtual ImageEffectFilter * getScrollbarEffect ()
返回滚动条所使用的组件效果。
virtual int getMinimumScrollbarThumbSize (ScrollBar &scrollbar)
返回滚动条滑块的最小长度,单位:像素。
virtual int getDefaultScrollbarWidth ()
返回滚动条默认的宽度。
virtual int getScrollbarButtonSize (ScrollBar &scrollbar)
返回滚动条按钮的长度,单位:像素。
virtual const Path getTickShape (float height)
返回是否已经选择的标记形状。
virtual const Path getCrossShape (float height)
返回是否已经选择的交叉形状。
virtual void drawTreeviewPlusMinusBox (Graphics &g, int x, int y, int w, int h, bool isPlus, bool isMouseOver)
绘制treeview的+或-。
virtual void fillTextEditorBackground (Graphics &g, int width, int height, TextEditor &textEditor)
virtual void drawTextEditorOutline (Graphics &g, int width, int height, TextEditor &textEditor)
virtual const Drawable * getDefaultFolderImage ()
virtual const Drawable * getDefaultDocumentFileImage ()
virtual void createFileChooserHeaderText (const String &title, const String &instructions, GlyphArrangement &destArrangement, int width)
virtual void drawFileBrowserRow (Graphics &g, int width, int height, const String &filename, Image *icon, const String &fileSizeDescription, const String &fileTimeDescription, bool isDirectory, bool isItemSelected, int itemIndex, DirectoryContentsDisplayComponent &component)
virtual Button * createFileBrowserGoUpButton ()
virtual void layoutFileBrowserComponent (FileBrowserComponent &browserComp, DirectoryContentsDisplayComponent *fileListComponent, FilePreviewComponent *previewComp, ComboBox *currentPathBox, TextEditor *filenameBox, Button *goUpButton)
virtual void drawBubble (Graphics &g, float tipX, float tipY, float boxX, float boxY, float boxW, float boxH)
virtual void drawPopupMenuBackground (Graphics &g, int width, int height)
填充弹出式菜单的背景。
virtual void drawPopupMenuItem (Graphics &g, int width, int height, bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu, const String &text, const String &shortcutKeyText, Image *image, const Colour *const textColour)
绘制弹出式菜单的某个菜单项。
virtual const Font getPopupMenuFont ()
返回弹出式菜单所使用的字型和字号。
virtual void drawPopupMenuUpDownArrow (Graphics &g, int width, int height, bool isScrollUpArrow)
virtual void getIdealPopupMenuItemSize (const String &text, bool isSeparator, int standardMenuItemHeight, int &idealWidth, int &idealHeight)
找到弹出式菜单的菜单项的最佳大小。
virtual int getMenuWindowFlags ()
virtual void drawMenuBarBackground (Graphics &g, int width, int height, bool isMouseOverBar, MenuBarComponent &menuBar)
virtual int getMenuBarItemWidth (MenuBarComponent &menuBar, int itemIndex, const String &itemText)
virtual const Font getMenuBarFont (MenuBarComponent &menuBar, int itemIndex, const String &itemText)
virtual void drawMenuBarItem (Graphics &g, int width, int height, int itemIndex, const String &itemText, bool isMouseOverItem, bool isMenuOpen, bool isMouseOverBar, MenuBarComponent &menuBar)
virtual void drawComboBox (Graphics &g, int width, int height, bool isButtonDown, int buttonX, int buttonY, int buttonW, int buttonH, ComboBox &box)
virtual const Font getComboBoxFont (ComboBox &box)
virtual Label * createComboBoxTextBox (ComboBox &box)
virtual void positionComboBoxText (ComboBox &box, Label &labelToPosition)
virtual void drawLabel (Graphics &g, Label &label)
virtual void drawLinearSlider (Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle style, Slider &slider)
virtual void drawLinearSliderBackground (Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle style, Slider &slider)
virtual void drawLinearSliderThumb (Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle style, Slider &slider)
virtual int getSliderThumbRadius (Slider &slider)
virtual void drawRotarySlider (Graphics &g, int x, int y, int width, int height, float sliderPosProportional, float rotaryStartAngle, float rotaryEndAngle, Slider &slider)
virtual Button * createSliderButton (bool isIncrement)
virtual Label * createSliderTextBox (Slider &slider)
virtual ImageEffectFilter * getSliderEffect ()
virtual void getTooltipSize (const String &tipText, int &width, int &height)
virtual void drawTooltip (Graphics &g, const String &text, int width, int height)
virtual Button * createFilenameComponentBrowseButton (const String &text)
virtual void layoutFilenameComponent (FilenameComponent &filenameComp, ComboBox *filenameBox, Button *browseButton)
virtual void drawCornerResizer (Graphics &g, int w, int h, bool isMouseOver, bool isMouseDragging)
virtual void drawResizableFrame (Graphics &g, int w, int h, const BorderSize &borders)
virtual void fillResizableWindowBackground (Graphics &g, int w, int h, const BorderSize &border, ResizableWindow &window)
virtual void drawResizableWindowBorder (Graphics &g, int w, int h, const BorderSize &border, ResizableWindow &window)
virtual void drawDocumentWindowTitleBar (DocumentWindow &window, Graphics &g, int w, int h, int titleSpaceX, int titleSpaceW, const Image *icon, bool drawTitleTextOnLeft)
virtual Button * createDocumentWindowButton (int buttonType)
virtual void positionDocumentWindowButtons (DocumentWindow &window, int titleBarX, int titleBarY, int titleBarW, int titleBarH, Button *minimiseButton, Button *maximiseButton, Button *closeButton, bool positionTitleBarButtonsOnLeft)
virtual int getDefaultMenuBarHeight ()
virtual DropShadower * createDropShadowerForComponent (Component *component)
virtual void drawStretchableLayoutResizerBar (Graphics &g, int w, int h, bool isVerticalBar, bool isMouseOver, bool isMouseDragging)
virtual void drawGroupComponentOutline (Graphics &g, int w, int h, const String &text, const Justification &position, GroupComponent &group)
virtual void createTabButtonShape (Path &p, int width, int height, int tabIndex, const String &text, Button &button, TabbedButtonBar::Orientation orientation, bool isMouseOver, bool isMouseDown, bool isFrontTab)
virtual void fillTabButtonShape (Graphics &g, const Path &path, const Colour &preferredBackgroundColour, int tabIndex, const String &text, Button &button, TabbedButtonBar::Orientation orientation, bool isMouseOver, bool isMouseDown, bool isFrontTab)
virtual void drawTabButtonText (Graphics &g, int x, int y, int w, int h, const Colour &preferredBackgroundColour, int tabIndex, const String &text, Button &button, TabbedButtonBar::Orientation orientation, bool isMouseOver, bool isMouseDown, bool isFrontTab)
virtual int getTabButtonOverlap (int tabDepth)
virtual int getTabButtonSpaceAroundImage ()
virtual int getTabButtonBestWidth (int tabIndex, const String &text, int tabDepth, Button &button)
virtual void drawTabButton (Graphics &g, int w, int h, const Colour &preferredColour, int tabIndex, const String &text, Button &button, TabbedButtonBar::Orientation orientation, bool isMouseOver, bool isMouseDown, bool isFrontTab)
virtual void drawTabAreaBehindFrontButton (Graphics &g, int w, int h, TabbedButtonBar &tabBar, TabbedButtonBar::Orientation orientation)
virtual Button * createTabBarExtrasButton ()
virtual void drawImageButton (Graphics &g, Image *image, int imageX, int imageY, int imageW, int imageH, const Colour &overlayColour, float imageOpacity, ImageButton &button)
virtual void drawTableHeaderBackground (Graphics &g, TableHeaderComponent &header)
virtual void drawTableHeaderColumn (Graphics &g, const String &columnName, int columnId, int width, int height, bool isMouseOver, bool isMouseDown, int columnFlags)
virtual void paintToolbarBackground (Graphics &g, int width, int height, Toolbar &toolbar)
virtual Button * createToolbarMissingItemsButton (Toolbar &toolbar)
virtual void paintToolbarButtonBackground (Graphics &g, int width, int height, bool isMouseOver, bool isMouseDown, ToolbarItemComponent &component)
virtual void paintToolbarButtonLabel (Graphics &g, int x, int y, int width, int height, const String &text, ToolbarItemComponent &component)
virtual void drawPropertyPanelSectionHeader (Graphics &g, const String &name, bool isOpen, int width, int height)
virtual void drawPropertyComponentBackground (Graphics &g, int width, int height, PropertyComponent &component)
virtual void drawPropertyComponentLabel (Graphics &g, int width, int height, PropertyComponent &component)
virtual const Rectangle< int > getPropertyComponentContentPosition (PropertyComponent &component)
void drawCallOutBoxBackground (CallOutBox &box, Graphics &g, const Path &path)
virtual void drawLevelMeter (Graphics &g, int width, int height, float level)
virtual void drawKeymapChangeButton (Graphics &g, int width, int height, Button &button, const String &keyDescription)
virtual void playAlertSound ()

静态Public成员函数

static LookAndFeel & getDefaultLookAndFeel () throw ()
返回当前的默认look-and-feel,以供某个组件使用,如果该组件尚未显式设置LAF。
static void setDefaultLookAndFeel (LookAndFeel *newDefaultLookAndFeel) throw ()
改变默认的look-and-feel。
static void drawGlassSphere (Graphics &g, float x, float y, float diameter, const Colour &colour, float outlineThickness) throw ()
比较有用的函数,用来绘制光晕、玻璃珠、LED式按钮等等。
static void drawGlassPointer (Graphics &g, float x, float y, float diameter, const Colour &colour, float outlineThickness, int direction) throw ()
static void drawGlassLozenge (Graphics &g, float x, float y, float width, float height, const Colour &colour, float outlineThickness, float cornerSize, bool flatOnLeft, bool flatOnRight, bool flatOnTop, bool flatOnBottom) throw ()
比较有用的函数,用来绘制光晕、椭圆形按钮(文本按钮)的外观。
static Drawable * loadDrawableFromData (const void *data, size_t numBytes)

友元

JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI ()
清除所有JUCE图形界面类的静态数据。

1 Like

详细说明

LookAndFeel对象用来定义所有JUCE控件的外观,其派生类可实现应用程序的“换肤”功能。

构造函数和析构函数文档

LookAndFeel::LookAndFeel ( )
创建默认的JUCE外观和感觉。

virtual LookAndFeel::~LookAndFeel ( ) [virtual]
析构函数。

1 Like

成员函数文档

static LookAndFeel& LookAndFeel::getDefaultLookAndFeel ( ) throw () [static]
返回当前的默认look-and-feel,以供某个组件使用,如果该组件尚未显式设置LAF。

参见:
setDefaultLookAndFeel
static void LookAndFeel::setDefaultLookAndFeel ( LookAndFeel * newDefaultLookAndFeel ) throw () [static]
改变默认的look-and-feel。

参数:
newDefaultLookAndFeel 要使用的新look-and-feel对象,如果设置为0,则恢复默认。当不再使用该对象时,要注意手工销毁之。
参见:
getDefaultLookAndFeel
const Colour LookAndFeel::findColour ( int colourId ) const throw ()
查找已经注册使用的某个颜色。

如果已经使用setColour()设置了某个颜色的ID,此函数将返回设置值。如果尚未设置,则返回Colours::black。

各种各样的颜色以ID的形式存储于颜色枚举中,可参见Slider::ColourIds、Label::ColourIds、TextEditor::ColourIds, TreeView::ColourIds等控件的颜色枚举。

如果正在寻找某个组件绘制所使用的颜色,最好不要直接调用此函数,而是使用:Component::findColour ()方法。此函数首先检测组件是否已经注册合适的颜色,如果没找到,则随后调用组件的LookAndFeel的findColour()方法。

参见:
setColour, Component::findColour, Component::setColour
void LookAndFeel::setColour ( int colourId,
const Colour & colour
) throw ()
注册一个要使用的颜色。

要获取更多信息,请参见:findColour(),

参见:
findColour, Component::findColour, Component::setColour
bool LookAndFeel::isColourSpecified ( int colourId ) const throw ()
如果给定的颜色由setColour()所设置,则返回true。

virtual const Typeface::Ptr LookAndFeel::getTypefaceForFont ( const Font & font [virtual]
void LookAndFeel::setDefaultSansSerifTypefaceName ( const String & newName )
允许您更改默认的sans-serif字体。

如果打算使用你自己的Typeface对象来替代默认的字体,而不是仅仅提供名称,比如:如果打算使用一个嵌入式字体,则必须重写getTypefaceForFont()以创建并返回一个字体。

virtual const MouseCursor LookAndFeel::getMouseCursorFor ( Component * component) [virtual]
重写此函数可使用自定义的鼠标指针。

virtual void LookAndFeel::drawButtonBackground ( Graphics & g,
Button & button,
const Colour & backgroundColour,
bool isMouseOverButton,
bool isButtonDown
) [virtual]
绘制一个具有菱形背景的标准按钮,

Reimplemented in OldSchoolLookAndFeel.

virtual const Font LookAndFeel::getFontForTextButton ( TextButton & button, [virtual]
virtual void LookAndFeel::drawButtonText ( Graphics & g,
TextButton & button,
bool isMouseOverButton,
bool isButtonDown
) [virtual]
绘制TextButton所显示的文本。

virtual void LookAndFeel::drawToggleButton ( Graphics & g,
ToggleButton & button,
bool isMouseOverButton,
bool isButtonDown
) [virtual]
绘制标准ToggleButton的内容。

重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::changeToggleButtonWidthToFitText ( ToggleButton & button, [virtual]
virtual void LookAndFeel::drawTickBox ( Graphics & g,
Component & component,
float x,
float y,
float w,
float h,
bool ticked,
bool isEnabled,
bool isMouseOverButton,
bool isButtonDown
) [virtual]
Reimplemented in OldSchoolLookAndFeel.

virtual AlertWindow* LookAndFeel::createAlertWindow ( const String & title,
const String & message,
const String & button1,
const String & button2,
const String & button3,
AlertWindow::AlertIconType iconType,
int numButtons,
Component * associatedComponent
) [virtual]
virtual void LookAndFeel::drawAlertBox ( Graphics & g,
AlertWindow & alert,
const Rectangle< int > & textArea,
TextLayout & textLayout
) [virtual]
virtual int LookAndFeel::getAlertBoxWindowFlags ( ) [virtual]
virtual int LookAndFeel::getAlertWindowButtonHeight ( ) [virtual]
virtual const Font LookAndFeel::getAlertWindowFont ( ) [virtual]
virtual void LookAndFeel::drawProgressBar ( Graphics & g,
ProgressBar & progressBar,
int width,
int height,
double progress,
const String & textToShow
) [virtual]
绘制进度条。

如果进度小于0或大于1.0,将绘制一个旋转的进度块并填充整个区域。也就是说,程序正忙,无法获取进度。可以使用当前时间为基准来播放动画效果。

(被具有进度条的AlertWindow所使用)。

Reimplemented in OldSchoolLookAndFeel.

virtual void LookAndFeel::drawSpinningWaitAnimation ( Graphics & g,
const Colour & colour,
int x,
int y,
int w,
int h,
) [virtual]
virtual void LookAndFeel::drawScrollbarButton ( Graphics & g,
ScrollBar & scrollbar,
int width,
int height,
int buttonDirection,
bool isScrollbarVertical,
bool isMouseOverButton,
bool isButtonDown
) [virtual]
绘制滚动条上的按钮。

参数:
g 要绘制的图形环境
scrollbar 滚动条本身
width 按钮宽度
height 按钮高度
buttonDirection 按钮方向:0为向上,1为向右,2为向下,3为向左
isScrollbarVertical true为垂直滚动条,false为水平滚动条
isMouseOverButton 鼠标是否指向按钮,如果按钮被按下,则为true
isButtonDown 是否按下了鼠标按钮
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::drawScrollbar ( Graphics & g,
ScrollBar & scrollbar,
int x,
int y,
int width,
int height,
bool isScrollbarVertical,
int thumbStartPosition,
int thumbSize,
bool isMouseOver,
bool isMouseDown
) [virtual]
绘制滚动条的滑块。

参数:
g 要绘制的图形环境
scrollbar 滚动条本身
x 滑块区域左边缘的X坐标
y 滑块区域顶边缘的Y坐标
width 滑块区域的宽度
height 滑块区域的高度
isScrollbarVertical true为垂直滚动条,false为水平滚动条
thumbStartPosition 垂直滚动条滑块的顶边缘y坐标,水平滚动条的左边缘x坐标
thumbSize 垂直滚动条的滑块高度,水平滚动条的滑块宽度。如果不打算绘制滑块,可设置为0。
isMouseOver 鼠标是否指向滑块区域,鼠标拖拉滑块时也为true
isMouseDown 鼠标是否拖拉滑块
重新实现:OldSchoolLookAndFeel

virtual ImageEffectFilter* LookAndFeel::getScrollbarEffect ( ) [virtual]
返回滚动条所使用的组件效果。

重新实现:OldSchoolLookAndFeel

virtual int LookAndFeel::getMinimumScrollbarThumbSize ( ScrollBar & scrollbar) [virtual]
返回滚动条滑块的最小长度,单位:像素。

virtual int LookAndFeel::getDefaultScrollbarWidth ( ) [virtual]
返回滚动条默认的宽度。

virtual int LookAndFeel::getScrollbarButtonSize ( ScrollBar & scrollbar) [virtual]
返回滚动条按钮的长度,单位:像素。

virtual const Path LookAndFeel::getTickShape ( float height) [virtual]
返回是否已经选择的标记形状。

virtual const Path LookAndFeel::getCrossShape ( float height) [virtual]
返回是否已经选择的交叉形状。

virtual void LookAndFeel::drawTreeviewPlusMinusBox ( Graphics & g,
int x,
int y,
int w,
int h,
bool isPlus,
bool isMouseOver
) [virtual]
绘制treeview的+或-。

virtual void LookAndFeel::fillTextEditorBackground ( Graphics & g,
int width,
int height,
TextEditor & textEditor
) [virtual]
virtual void LookAndFeel::drawTextEditorOutline ( Graphics & g,
int width,
int height,
TextEditor & textEditor
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual const Drawable* LookAndFeel::getDefaultFolderImage ( ) [virtual]
virtual const Drawable* LookAndFeel::getDefaultDocumentFileImage ( ) [virtual]
virtual void LookAndFeel::createFileChooserHeaderText ( const String & title,
const String & instructions,
GlyphArrangement & destArrangement,
int width
) [virtual]
virtual void LookAndFeel::drawFileBrowserRow ( Graphics & g,
int width,
int height,
const String & filename,
Image * icon,
const String & fileSizeDescription,
const String & fileTimeDescription,
bool isDirectory,
bool isItemSelected,
int itemIndex,
DirectoryContentsDisplayComponent & component
) [virtual]
virtual Button* LookAndFeel::createFileBrowserGoUpButton ( ) [virtual]
virtual void LookAndFeel::layoutFileBrowserComponent ( FileBrowserComponent & browserComp,
DirectoryContentsDisplayComponent * fileListComponent,
FilePreviewComponent * previewComp,
ComboBox * currentPathBox,
TextEditor * filenameBox,
Button * goUpButton
) [virtual]
virtual void LookAndFeel::drawBubble ( Graphics & g,
float tipX,
float tipY,
float boxX,
float boxY,
float boxW,
float boxH
) [virtual]
virtual void LookAndFeel::drawPopupMenuBackground ( Graphics & g,
int width,
int height
) [virtual]
填充弹出式菜单的背景。

重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::drawPopupMenuItem ( Graphics & g,
int width,
int height,
bool isSeparator,
bool isActive,
bool isHighlighted,
bool isTicked,
bool hasSubMenu,
const String & text,
const String & shortcutKeyText,
Image * image,
const Colour *const textColour
) [virtual]
绘制弹出式菜单的某个菜单项。

1 Like

virtual const Font LookAndFeel::getPopupMenuFont ( ) [virtual]
返回弹出式菜单所使用的字型和字号。

virtual void LookAndFeel::drawPopupMenuUpDownArrow ( Graphics & g,
int width,
int height,
bool isScrollUpArrow
) [virtual]
virtual void LookAndFeel::getIdealPopupMenuItemSize ( const String & text,
bool isSeparator,
int standardMenuItemHeight,
int idealWidth,
int idealHeight
) [virtual]
找到弹出式菜单的菜单项的最佳大小。

virtual int LookAndFeel::getMenuWindowFlags ( ) [virtual]
virtual void LookAndFeel::drawMenuBarBackground ( Graphics & g,
int width,
int height,
bool isMouseOverBar,
MenuBarComponent & menuBar
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual int LookAndFeel::getMenuBarItemWidth ( MenuBarComponent & menuBar,
int itemIndex,
const String & itemText
) [virtual]
virtual const Font LookAndFeel::getMenuBarFont ( MenuBarComponent & menuBar,
int itemIndex,
const String & itemText
) [virtual]
virtual void LookAndFeel::drawMenuBarItem ( Graphics & g,
int width,
int height,
int itemIndex,
const String & itemText,
bool isMouseOverItem,
bool isMenuOpen,
bool isMouseOverBar,
MenuBarComponent & menuBar
) [virtual]
virtual void LookAndFeel::drawComboBox ( Graphics & g,
int width,
int height,
bool isButtonDown,
int buttonX,
int buttonY,
int buttonW,
int buttonH,
ComboBox & box
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual const Font LookAndFeel::getComboBoxFont ( ComboBox & box) [virtual]
重新实现:OldSchoolLookAndFeel

virtual Label* LookAndFeel::createComboBoxTextBox ( ComboBox & box) [virtual]
virtual void LookAndFeel::positionComboBoxText ( ComboBox & box,
Label & labelToPosition
) [virtual]
virtual void LookAndFeel::drawLabel ( Graphics & g,
Label & label
) [virtual]
virtual void LookAndFeel::drawLinearSlider ( Graphics & g,
int x,
int y,
int width,
int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style,
Slider & slider
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::drawLinearSliderBackground ( Graphics & g,
int x,
int y,
int width,
int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style,
Slider & slider
) [virtual]
virtual void LookAndFeel::drawLinearSliderThumb ( Graphics & g,
int x,
int y,
int width,
int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style,
Slider & slider
) [virtual]
virtual int LookAndFeel::getSliderThumbRadius ( Slider & slider) [virtual]
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::drawRotarySlider ( Graphics & g,
int x,
int y,
int width,
int height,
float sliderPosProportional,
float rotaryStartAngle,
float rotaryEndAngle,
Slider & slider
) [virtual]
virtual Button* LookAndFeel::createSliderButton ( bool isIncrement ) [virtual]
重新实现:OldSchoolLookAndFeel

virtual Label* LookAndFeel::createSliderTextBox ( Slider & slider) [virtual]
virtual ImageEffectFilter* LookAndFeel::getSliderEffect ( ) [virtual]
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::getTooltipSize ( const String & tipText,
int width,
int height
) [virtual]
virtual void LookAndFeel::drawTooltip ( Graphics & g,
const String & text,
int width,
int height,
) [virtual]
virtual Button* LookAndFeel::createFilenameComponentBrowseButton ( const String & text) [virtual]
virtual void LookAndFeel::layoutFilenameComponent ( FilenameComponent & filenameComp,
ComboBox * filenameBox,
Button * browseButton
) [virtual]
virtual void LookAndFeel::drawCornerResizer ( Graphics & g,
int w,
int h,
bool isMouseOver,
bool isMouseDragging
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::drawResizableFrame ( Graphics & g,
int w,
int h,
const BorderSize & borders
) [virtual]
virtual void LookAndFeel::fillResizableWindowBackground ( Graphics & g,
int w,
int h,
const BorderSize & border,
ResizableWindow & window
) [virtual]
virtual void LookAndFeel::drawResizableWindowBorder ( Graphics & g,
int w,
int h,
const BorderSize & border,
ResizableWindow & window
) [virtual]
virtual void LookAndFeel::drawDocumentWindowTitleBar ( DocumentWindow & window,
Graphics & g,
int w,
int h,
int titleSpaceX,
int titleSpaceW,
const Image * icon,
bool drawTitleTextOnLeft
) [virtual]
virtual Button* LookAndFeel::createDocumentWindowButton ( int buttonType ) [virtual]
重新实现:OldSchoolLookAndFeel

virtual void LookAndFeel::positionDocumentWindowButtons ( DocumentWindow & window,
int titleBarX,
int titleBarY,
int titleBarW,
int titleBarH,
Button * minimiseButton,
Button * maximiseButton,
Button * closeButton,
bool positionTitleBarButtonsOnLeft
) [virtual]
重新实现:OldSchoolLookAndFeel

virtual int LookAndFeel::getDefaultMenuBarHeight ( ) [virtual]
virtual DropShadower* LookAndFeel::createDropShadowerForComponent ( Component * component) [virtual]
virtual void LookAndFeel::drawStretchableLayoutResizerBar ( Graphics & g,
int w,
int h,
bool isVerticalBar,
bool isMouseOver,
bool isMouseDragging
) [virtual]
virtual void LookAndFeel::drawGroupComponentOutline ( Graphics & g,
int w,
int h,
const String & text,
const Justification & position,
GroupComponent & group
) [virtual]
virtual void LookAndFeel::createTabButtonShape ( Path & p,
int width,
int height,
int tabIndex,
const String & text,
Button & button,
TabbedButtonBar::Orientation orientation,
bool isMouseOver,
bool isMouseDown,
bool isFrontTab
) [virtual]
virtual void LookAndFeel::fillTabButtonShape ( Graphics & g,
const Path & path,
const Colour & preferredBackgroundColour,
int tabIndex,
const String & text,
Button & button,
TabbedButtonBar::Orientation orientation,
bool isMouseOver,
bool isMouseDown,
bool isFrontTab
) [virtual]
virtual void LookAndFeel::drawTabButtonText ( Graphics & g,
int x,
int y,
int w,
int h,
const Colour & preferredBackgroundColour,
int tabIndex,
const String & text,
Button & button,
TabbedButtonBar::Orientation orientation,
bool isMouseOver,
bool isMouseDown,
bool isFrontTab
) [virtual]
virtual int LookAndFeel::getTabButtonOverlap ( int tabDepth ) [virtual]
virtual int LookAndFeel::getTabButtonSpaceAroundImage ( ) [virtual]
virtual int LookAndFeel::getTabButtonBestWidth ( int tabIndex,
const String & text,
int tabDepth,
Button & button
) [virtual]
virtual void LookAndFeel::drawTabButton ( Graphics & g,
int w,
int h,
const Colour & preferredColour,
int tabIndex,
const String & text,
Button & button,
TabbedButtonBar::Orientation orientation,
bool isMouseOver,
bool isMouseDown,
bool isFrontTab
) [virtual]
virtual void LookAndFeel::drawTabAreaBehindFrontButton ( Graphics & g,
int w,
int h,
TabbedButtonBar & tabBar,
TabbedButtonBar::Orientation {0}orientation{/0},
) [virtual]
virtual Button* LookAndFeel::createTabBarExtrasButton ( ) [virtual]
virtual void LookAndFeel::drawImageButton ( Graphics & g,
Image * image,
int imageX,
int imageY,
int imageW,
int imageH,
const Colour & overlayColour,
float imageOpacity,
ImageButton & button
) [virtual]
virtual void LookAndFeel::drawTableHeaderBackground ( Graphics & g,
TableHeaderComponent & header
) [virtual]
virtual void LookAndFeel::drawTableHeaderColumn ( Graphics & g,
const String & columnName,
int columnId,
int width,
int height,
bool isMouseOver,
bool isMouseDown,
int columnFlags
) [virtual]
virtual void LookAndFeel::paintToolbarBackground ( Graphics & g,
int width,
int height,
Toolbar & toolbar
) [virtual]
virtual Button* LookAndFeel::createToolbarMissingItemsButton ( Toolbar & toolbar) [virtual]
virtual void LookAndFeel::paintToolbarButtonBackground ( Graphics & g,
int width,
int height,
bool isMouseOver,
bool isMouseDown,
ToolbarItemComponent & component
) [virtual]
virtual void LookAndFeel::paintToolbarButtonLabel ( Graphics & g,
int x,
int y,
int width,
int height,
const String & text,
ToolbarItemComponent & component
) [virtual]
virtual void LookAndFeel::drawPropertyPanelSectionHeader ( Graphics & g,
const String & name,
bool isOpen,
int width,
int height
) [virtual]
virtual void LookAndFeel::drawPropertyComponentBackground ( Graphics & g,
int width,
int height,
PropertyComponent & component
) [virtual]
virtual void LookAndFeel::drawPropertyComponentLabel ( Graphics & g,
int width,
int height,
PropertyComponent & component
) [virtual]
virtual const Rectangle LookAndFeel::getPropertyComponentContentPosition ( PropertyComponent & component) [virtual]
void LookAndFeel::drawCallOutBoxBackground ( CallOutBox & box,
Graphics & g,
const Path & path
)
virtual void LookAndFeel::drawLevelMeter ( Graphics & g,
int width,
int height,
float level
) [virtual]
virtual void LookAndFeel::drawKeymapChangeButton ( Graphics & g,
int width,
int height,
Button & button,
const String & keyDescription
) [virtual]
virtual void LookAndFeel::playAlertSound ( ) [virtual]
static void LookAndFeel::drawGlassSphere ( Graphics & g,
float x,
float y,
float diameter,
const Colour & colour,
float outlineThickness
) throw () [static]
比较有用的函数,用来绘制光晕、玻璃珠、LED式按钮等等。

static void LookAndFeel::drawGlassPointer ( Graphics & g,
float x,
float y,
float diameter,
const Colour & colour,
float outlineThickness,
int direction
) throw () [static]
static void LookAndFeel::drawGlassLozenge ( Graphics & g,
float x,
float y,
float width,
float height,
const Colour & colour,
float outlineThickness,
float cornerSize,
bool flatOnLeft,
bool flatOnRight,
bool flatOnTop,
bool flatOnBottom
) throw () [static]
比较有用的函数,用来绘制光晕、椭圆形按钮(文本按钮)的外观。

static Drawable* LookAndFeel::loadDrawableFromData ( const void * data,
size_t numBytes
) [static]

友元和相关函数文档

JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI ( ) [friend]
清除JUCE界面类所使用的所有静态数据。

如果采用嵌入式的方法使用JUCE类库,而不是使用START_JUCE_APPLICATION宏来启动应用程序,在关闭事件处理代码中调用此函数,以清除程序中所使用的JUCE对象。

参见:
initialiseJuce_GUI(), initialiseJuce_NonGUI()

定义该类的头文件:
juce_LookAndFeel.h

1 Like

[size=200]String 字符串类[/size]

JUCE字符串类。 更多…

所有成员

class Concatenator
一个用于提高性能的辅助类,用于连接较大的字符串。 更多…

Public成员函数

String () throw ()
创建一个空字符串。 
String (const String &other) throw ()
创建另一个字符串的副本。 
String (const char *text)
由零结束符的字符数组创建一个字符串。 
String (const char *text, size_t maxChars)
由字符数组创建一个字符串。 
String (const juce_wchar *unicodeText)
由零结束符unicode字符数组创建一个字符串。 
String (const juce_wchar *unicodeText, size_t maxChars)
由unicode字符数组创建一个字符串。 
~String () throw ()
 析构函数。 

int hashCode () const throw ()
生成该字符串可能唯一的32位哈希编码(hashcode)。
int64 hashCode64 () const throw ()
生成该字符串可能唯一的64位哈希编码(hashcode)。
int length () const throw ()
返回字符串中的字符数。
String & operator= (const String &other) throw ()
用另一个字符串替换该字符串的内容。
String & operator+= (const juce_wchar *textToAppend)
将另一个字符串追加到该字符串的末尾。
String & operator+= (const String &stringToAppend)
将另一个字符串追加到该字符串的末尾。
String & operator+= (char characterToAppend)
将字符追加到该字符串的末尾。
String & operator+= (juce_wchar characterToAppend)
将字符追加到该字符串的末尾。
String & operator+= (int numberToAppend)
将一个十进制数字追加到此字符串的末尾。
String & operator+= (unsigned int numberToAppend)
将一个十进制数字追加到此字符串的末尾。
void append (const juce_wchar *textToAppend, int maxCharsToTake)
将一个字符数组追加到该字符串的末尾。
bool isEmpty () const throw ()
如果该字符串不包含任何字符,则返回true。
bool isNotEmpty () const throw ()
如果该字符串至少包含一个字符,则返回true。
bool equalsIgnoreCase (const String &other) const throw ()
字符串比较,忽略大小写。
bool equalsIgnoreCase (const juce_wchar *other) const throw ()
字符串比较,忽略大小写。
bool equalsIgnoreCase (const char *other) const throw ()
字符串比较,忽略大小写。
int compare (const String &other) const throw ()
字符串比较,区分大小写。
int compare (const char *other) const throw ()
字符串比较,区分大小写。
int compare (const juce_wchar *other) const throw ()
字符串比较,区分大小写。
int compareIgnoreCase (const String &other) const throw ()
字符串比较,忽略大小写。
int compareLexicographically (const String &other) const throw ()
字符串比较,按字典排序。
bool startsWith (const String &text) const throw ()
测试该字符串的开始是否为另一个字符串。
bool startsWithChar (juce_wchar character) const throw ()
测试该字符串的开头是否为特定的字符。
bool startsWithIgnoreCase (const String &text) const throw ()
测试该字符串的开始是否为另一个字符串。
bool endsWith (const String &text) const throw ()
测试该字符串的最后部分是否为另一个字符串。
bool endsWithChar (juce_wchar character) const throw ()
测试该字符串是否以特定的字符结尾。
bool endsWithIgnoreCase (const String &text) const throw ()
测试该字符串的最后部分是否为另一个字符串。
bool contains (const String &text) const throw ()
测试该字符串是否包含另一个字符串。
bool containsChar (juce_wchar character) const throw ()
测试该字符串是否包含特定的字符。
bool containsIgnoreCase (const String &text) const throw ()
测试该字符串是否包含另一个字符串。
bool containsWholeWord (const String &wordToLookFor) const throw ()
测试该字符串是否包含另一个字符串。
bool containsWholeWordIgnoreCase (const String &wordToLookFor) const throw ()
测试该字符串是否包含另一个字符串。
int indexOfWholeWord (const String &wordToLookFor) const throw ()
查找另一个字符串的实例,前提是参数字符串为字典单词(不包含数字和特殊符号的字符串)。
int indexOfWholeWordIgnoreCase (const String &wordToLookFor) const throw ()
查找另一个字符串的实例,前提是参数字符串为字典单词(不包含数字和特殊符号的字符串)。
bool containsAnyOf (const String &charactersItMightContain) const throw ()
测试两个字符串是否有相同的字符。
bool containsOnly (const String &charactersItMightContain) const throw ()
检测两个字符串是否有相同字符。
bool containsNonWhitespaceChars () const throw ()
如果此字符串中包含非空白字符则返回true。
bool matchesWildcard (const String &wildcard, bool ignoreCase) const throw ()
如果该字符串匹配给出的通配符表达式,则返回true。
int indexOfChar (juce_wchar characterToLookFor) const throw ()
搜索此字符串内的某个字符。
int indexOfChar (int startIndex, juce_wchar characterToLookFor) const throw ()
搜索此字符串内的某个字符。
int indexOfAnyOf (const String &charactersToLookFor, int startIndex=0, bool ignoreCase=false) const throw ()
返回与给出的字符串中的任意一个字符相匹配的字符的索引位置。
int indexOf (const String &text) const throw ()
在该字符串中搜索给出的子字符串。
int indexOf (int startIndex, const String &textToLookFor) const throw ()
在该字符串中搜索给出的子字符串。
int indexOfIgnoreCase (const String &textToLookFor) const throw ()
在该字符串中搜索给出的子字符串。
int indexOfIgnoreCase (int startIndex, const String &textToLookFor) const throw ()
在该字符串中搜索给出的子字符串。
int lastIndexOfChar (juce_wchar character) const throw ()
在该字符串中搜索给出的字符(由后向前查找)。
int lastIndexOf (const String &textToLookFor) const throw ()
在该字符串中搜索给出的字符串(由后向前查找)。
int lastIndexOfIgnoreCase (const String &textToLookFor) const throw ()
在该字符串中搜索给出的字符串(由后向前查找)。
int lastIndexOfAnyOf (const String &charactersToLookFor, bool ignoreCase=false) const throw ()
由后至前搜索,如果找到给定字符串的任意一个字符,则返回该字符所在的索引位置。
const juce_wchar & operator[] (int index) const throw ()
按索引值返回该字符串的某个字符。
juce_wchar & operator[] (int index)
返回字符串中的某个字符,此方法也可以直接给该字符赋值,以改变之。
juce_wchar getLastCharacter () const throw ()
返回字符串的最后一个字符。
const String substring (int startIndex, int endIndex) const
提取字符串的部分内容。
const String substring (int startIndex) const
提取字符串的后半部分。
const String dropLastCharacters (int numberToDrop) const
返回去掉最后几个字符的该字符串。
const String getLastCharacters (int numCharacters) const
返回该字符串最后的部分,返回几个字符由给出的参数确定。
const String fromFirstOccurrenceOf (const String &substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
返回由给定的子字符串为开始的后半部分内容。
const String fromLastOccurrenceOf (const String &substringToFind, bool includeSubStringInResult, bool ignoreCase) const
返回由给定的子字符串为结尾的一部分内容。
const String upToFirstOccurrenceOf (const String &substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
返回此字符串开头的一部分,直至遇到给出的字符串。
const String upToLastOccurrenceOf (const String &substringToFind, bool includeSubStringInResult, bool ignoreCase) const
返回此字符串开头的一部分,直至给出的字符串不再出现。
const String trim () const
删除开头和末尾的空格字符,而后返回。
const String trimStart () const
删除开头的空格字符,而后返回。
const String trimEnd () const
删除末尾的空格字符,而后返回。
const String trimCharactersAtStart (const String &charactersToTrim) const
从开始处删除给定的字符串,而后返回。
const String trimCharactersAtEnd (const String &charactersToTrim) const
由后往前删除给定的字符串,而后返回。
const String toUpperCase () const
返回此字符串的大写版本。
const String toLowerCase () const
返回此字符串的小写版本。
const String replaceSection (int startIndex, int numCharactersToReplace, const String &stringToInsert) const
用另一个字符串替换该字符串的一部分内容。
const String replace (const String &stringToReplace, const String &stringToInsertInstead, bool ignoreCase=false) const
用另一个字符串替换本字符串。
const String replaceCharacter (juce_wchar characterToReplace, juce_wchar characterToInsertInstead) const
替换该字符串的某个字符。
const String replaceCharacters (const String &charactersToReplace, const String &charactersToInsertInstead) const
替换该字符串中的某些字符。
const String retainCharacters (const String &charactersToRetain) const
仅保留参数字符串所包含的字符。
const String removeCharacters (const String &charactersToRemove) const
移除某些字符。
const String initialSectionContainingOnly (const String &permittedCharacters) const
从该字符串的开头处返回不包含特定字符集合的内容。
const String initialSectionNotContaining (const String &charactersToStopAt) const
从该字符串的开头处返回不包含特定字符集合的内容。
bool isQuotedString () const
检查该字符串是否以引号开头。
const String unquoted () const
如包含引号则删之。
const String quoted (juce_wchar quoteCharacter= ‘"’) const
前后添加引号。
const String paddedLeft (juce_wchar padCharacter, int minimumLength) const
指定的字符重复添加到该字符串的开始处,直到总长度达到所指定的长度。
const String paddedRight (juce_wchar padCharacter, int minimumLength) const
指定的字符重复添加到该字符串的结束处,直到总长度达到所指定的长度。
String (int decimalInteger)
创建一个32位整数的十进制数字文本字符串。
String (unsigned int decimalInteger)
创建一个32位正整数的十进制数字文本字符串。
String (short decimalInteger)
创建一个16位整数的十进制数字文本字符串。
String (unsigned short decimalInteger)
创建一个16位正整数的十进制数字文本字符串。
String (int64 largeIntegerValue)
创建一个64位整数的十进制数字文本字符串。
String (uint64 largeIntegerValue)
创建一个64位正整数的十进制数字文本字符串。
String (float floatValue, int numberOfDecimalPlaces=0)
创建一个浮点型数字的文本字符串。
String (double doubleValue, int numberOfDecimalPlaces=0)
创建一个浮点型数字的文本字符串。
int getIntValue () const throw ()
将字符串的值转为十进制数字(最多32位大小)。
int64 getLargeIntValue () const throw ()
将字符串的值转为十进制数字(最多64位大小)。
int getTrailingIntValue () const throw ()
提取字符串结尾的十进制数字。
float getFloatValue () const throw ()
提取字符串的浮点型数字。
double getDoubleValue () const throw ()
提取字符串的浮点型数字。
int getHexValue32 () const throw ()
提取字符串的16进制数字。
int64 getHexValue64 () const throw ()
提取字符串的16进制数字。
operator const juce_wchar * () const throw ()
返回此字符串的unicode版本。
operator juce_wchar * () throw ()
返回此字符串的unicode版本。
const char * toUTF8 () const
返回此字符串的UTF-8版本的指针。
int getNumBytesAsUTF8 () const throw ()
返回此字符串表示UTF8格式所需的字节数。
int copyToUTF8 (char *destBuffer, int maxBufferSizeBytes) const throw ()
将字符串作为UTF-8字符复制到缓冲区中。
const char * toCString () const
返回此字符串使用默认的8位多字节系统编码的版本。
int getNumBytesAsCString () const throw ()
返回此字符串的字节数。
int copyToCString (char *destBuffer, int maxBufferSizeBytes) const throw ()
将字符串复制到缓冲区中。
void copyToUnicode (juce_wchar *destBuffer, int maxCharsToCopy) const throw ()
将字符串复制到unicode缓冲区中。
void preallocateStorage (size_t numCharsNeeded)
为此字符串增加内部分配的存储区。
void swapWith (String &other) throw ()
交换两个字符串的内容。

1 Like

静态Public成员函数

static const String charToString (juce_wchar character)
将单个字符转换为字符串。
static const String repeatedString (const String &stringToRepeat, int numberOfTimesToRepeat)
将一个字符串重复多次后形成一个新的字符串。
static const String createStringFromData (const void *data, int size)
将一个未知格式的数据转换为字符串。
static const String formatted (const juce_wchar *formatString,…)
以printf样式为参数列表来创建一个字符串。
static const String toHexString (int number)
创建十进制数字的32位十六进制数字字符串。
static const String toHexString (int64 number)
创建十进制数字的64位十六进制数字字符串。
static const String toHexString (short number)
创建十进制数字的16位十六进制数字。
static const String toHexString (const unsigned char *data, int size, int groupSize=1)
创建一个字符串,其中包含块的二进制数据的十六进制转储。
static const String fromUTF8 (const char *utf8buffer, int bufferSizeBytes=-1)
从UTF-8编码的缓冲区中创建一个String。

静态Public属性

static const String empty
清空字符串的内容,使之变成空字符串。

详细说明

JUCE字符串类。

JUCE字符串类使用引用计数的内部表示形式,提供高效而卓越的性能,包含了大量极具实用价值的方法。

参见:
StringArray, StringPairArray

构造函数和析构函数文档

String::String ( ) throw ()
创建一个空字符串。

参见:
empty
String::String ( const String & other ) throw ()
创建另一个字符串的副本(拷贝构造函数)。

String::String ( const char * text )
由零结束符的字符数组创建一个字符串。

假定字符串存储为系统默认的编码格式。

String::String ( const char * text,
size_t maxChars
)
由字符数组创建一个字符串。

字符串将使用前maxChars个字符(或少于此值,如果字符串实际上较短)。

String::String ( const juce_wchar * unicodeText )
由零结束符unicode字符数组创建一个字符串。

String::String ( const juce_wchar * unicodeText,
size_t maxChars
)
由unicode字符数组创建一个字符串。

字符串将使用前maxChars个字符(或少于此值,如果字符串实际上较短)。

String::~String ( ) throw ()
析构函数。

String::String ( int decimalInteger ) [explicit]
创建一个32位整数的十进制数字文本字符串。

参见:
getIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( unsigned int decimalInteger ) [explicit]
创建一个32位正整数的十进制数字文本字符串。

参见:
getIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( short decimalInteger ) [explicit]
创建一个16位整数的十进制数字文本字符串。

参见:
getIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( unsigned short decimalInteger ) [explicit]
创建一个16位正整数的十进制数字文本字符串。

参见:
getIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( int64 largeIntegerValue ) [explicit]
创建一个64位整数的十进制数字文本字符串。

参见:
getLargeIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( uint64 largeIntegerValue ) [explicit]
创建一个64位正整数的十进制数字文本字符串。

参见:
getLargeIntValue, getFloatValue, getDoubleValue, toHexString
String::String ( float floatValue,
int numberOfDecimalPlaces = 0
) [explicit]
创建一个浮点型数字的文本字符串。

参数:
floatValue 要转换为字符串的数值
numberOfDecimalPlaces 如果大于0,则小数位为该值,并且不使用指数表示法。小于等于0的情况下,如有必要则使用指数表示法。
参见:
getDoubleValue, getIntValue
String::String ( double doubleValue,
int numberOfDecimalPlaces = 0
) [explicit]
创建一个浮点型数字的文本字符串。

参数:
doubleValue 要转换为字符串的数值
numberOfDecimalPlaces 如果大于0,则小数位为该值,并且不使用指数表示法。 小于等于0的情况下,如有必要,则使用指数表示法。
参见:
getFloatValue, getIntValue

1 Like

成员函数文档

static const String String::charToString ( juce_wchar character ) [static]
将单个字符转换为字符串。

int String::hashCode ( ) const throw ()
生成该字符串可能唯一的32位哈希编码(hashcode)。

int64 String::hashCode64 ( ) const throw ()
生成该字符串可能唯一的64位哈希编码(hashcode)。

int String::length ( ) const throw ()
返回字符串中的字符数。

String& String::operator= ( const String & other ) throw ()
用另一个字符串替换该字符串的内容。

String& String::operator+= ( const juce_wchar * textToAppend )
将另一个字符串追加到该字符串的末尾。

String& String::operator+= ( const String & stringToAppend )
将另一个字符串追加到该字符串的末尾。

String& String::operator+= ( char characterToAppend )
将字符追加到该字符串的末尾。

String& String::operator+= ( juce_wchar characterToAppend )
将字符追加到该字符串的末尾。

String& String::operator+= ( int numberToAppend )
将一个十进制数字追加到此字符串的末尾。

String& String::operator+= ( unsigned int numberToAppend )
将一个十进制数字追加到此字符串的末尾。

void String::append ( const juce_wchar * textToAppend,
int maxCharsToTake
)
将一个字符数组追加到该字符串的末尾。

参数:
textToAppend 要添加的字符串
maxCharsToTake 添加前几个字符
bool String::isEmpty ( ) const throw ()
如果该字符串不包含任何字符,则返回true。

注意:还可使用判断非空的函数isNotEmpty()。

参见:
containsNonWhitespaceChars()
bool String::isNotEmpty ( ) const throw ()
如果该字符串至少包含一个字符,则返回true。

注意:还可使用判断是否为空的函数isEmpty()。

参见:
containsNonWhitespaceChars()
bool String::equalsIgnoreCase ( const String & other ) const throw ()
字符串比较,忽略大小写。

bool String::equalsIgnoreCase ( const juce_wchar * other ) const throw ()
字符串比较,忽略大小写。

bool String::equalsIgnoreCase ( const char * other ) const throw ()
字符串比较,忽略大小写。

int String::compare ( const String & other ) const throw ()
字符串比较,区分大小写。

返回:
如果两个字符串相同则返回0。如果此字符串的字典顺序在前,则返回负数,否则返回正数。
int String::compare ( const char * other ) const throw ()
字符串比较,区分大小写。

返回:
如果两个字符串相同则返回0。如果此字符串的字典顺序在前,则返回负数,否则返回正数。
int String::compare ( const juce_wchar * other ) const throw ()
字符串比较,区分大小写。

返回:
如果两个字符串相同则返回0。如果此字符串的字典顺序在前,则返回负数,否则返回正数。
int String::compareIgnoreCase ( const String & other ) const throw ()
字符串比较,忽略大小写。

返回:
如果两个字符串相同则返回0。如果此字符串的字典顺序在前,则返回负数,否则返回正数。
int String::compareLexicographically ( const String & other ) const throw ()
字符串比较,按字典排序。

比较操作不区分大小写,并忽略非字母和数字性质的字符的排序。

返回:
如果两个字符串相同则返回0。如果此字符串的字典顺序在前,则返回负数,否则返回正数。
bool String::startsWith ( const String & text ) const throw ()
测试该字符串的开始是否为另一个字符串。

如果参数为空字符串,则始终返回true。此方法区分大小写。

bool String::startsWithChar ( juce_wchar character ) const throw ()
测试该字符串的开头是否为特定的字符。

如果字符为0,则始终返回false。此方法区分大小写。

bool String::startsWithIgnoreCase ( const String & text ) const throw ()
测试该字符串的开始是否为另一个字符串。

如果参数为空字符串,则始终返回true。 此方法区分大小写。

bool String::endsWith ( const String & text ) const throw ()
测试该字符串的最后部分是否为另一个字符串。

如果参数为空字符串,则始终返回true。 此方法区分大小写。

bool String::endsWithChar ( juce_wchar character ) const throw ()
测试该字符串是否以特定的字符结尾。

如果字符为0,则始终返回false。 此方法区分大小写。

bool String::endsWithIgnoreCase ( const String & text ) const throw ()
测试该字符串的最后部分是否为另一个字符串。

如果参数为空字符串,则始终返回true。 此方法区分大小写。

bool String::contains ( const String & text ) const throw ()
测试该字符串是否包含另一个字符串。

如果参数为空字符串,则始终返回true。 此方法区分大小写。

bool String::containsChar ( juce_wchar character ) const throw ()
测试该字符串是否包含特定的字符。

此方法区分大小写。

bool String::containsIgnoreCase ( const String & text ) const throw ()
测试该字符串是否包含另一个字符串。

此方法区分大小写。

bool String::containsWholeWord ( const String & wordToLookFor ) const throw ()
测试该字符串是否包含另一个字符串。

返回:
如果该字符串包含给出的参数,则返回true。注意参数字符串的首尾不能是非字母和数字性质的字符。
参见:
indexOfWholeWord, containsWholeWordIgnoreCase
bool String::containsWholeWordIgnoreCase ( const String & wordToLookFor ) const throw ()
测试该字符串是否包含另一个字符串。

返回:
如果该字符串包含给出的参数,则返回true。注意参数字符串的首尾不能是非字母和数字性质的字符。
参见:
indexOfWholeWordIgnoreCase, containsWholeWord
int String::indexOfWholeWord ( const String & wordToLookFor ) const throw ()
查找另一个字符串的实例,前提是参数字符串为字典单词(不包含数字和特殊符号的字符串)。

返回:
此方法返回参数字符串在本字符串的起始位置。注意,参数字符串的首尾不能是非字母和数字性质的字符。如果不包含参数字符串,则返回-1。
参见:
indexOfWholeWordIgnoreCase, containsWholeWord
int String::indexOfWholeWordIgnoreCase ( const String & wordToLookFor ) const throw ()
查找另一个字符串的实例,前提是参数字符串为字典单词(不包含数字和特殊符号的字符串)。

返回:
此方法返回参数字符串在本字符串的起始位置。注意,参数字符串的首尾不能是非字母和数字性质的字符。 如果不包含参数字符串,则返回-1。
参见:
indexOfWholeWord, containsWholeWordIgnoreCase
bool String::containsAnyOf ( const String & charactersItMightContain ) const throw ()
测试两个字符串是否有相同的字符。

此方法区分大小写。

返回:
如果该字符串包含参数字符串中的任意一个字符,则返回true。
bool String::containsOnly ( const String & charactersItMightContain ) const throw ()
检测两个字符串是否有相同字符。

此方法区分大小写。

返回:
如果参数字符串中的所有字符均未出现在该字符串中,则返回false。如果该字符串为空,则始终返回true。
bool String::containsNonWhitespaceChars ( ) const throw ()
如果此字符串中包含非空白字符则返回true。

如果字符串包含空格字符,或者为空,则返回false。

此函数等价于:myString.trim().isNotEmpty()

bool String::matchesWildcard ( const String & wildcard,
bool ignoreCase
) const throw ()
如果该字符串匹配给出的通配符表达式,则返回true。

比如:String (“abcdef”).matchesWildcard ("*DEF", true); // 返回true。

注意:此函数并非规范的正则表达式,仅支持“*”和“?”这两种通配符。主要用于文件名通配。

int String::indexOfChar ( juce_wchar characterToLookFor ) const throw ()
搜索此字符串内的某个字符。

此方法区分大小写。

返回:
返回值为第一次出现的位置。如果未找到则返回-1。
int String::indexOfChar ( int startIndex,
juce_wchar characterToLookFor
) const throw ()
搜索此字符串内的某个字符。

此方法区分大小写。

参数:
startIndex 从该位置起向后搜索
characterToLookFor 要查找的字符
返回:
返回值为第一次出现的位置。如果未找到则返回-1。
int String::indexOfAnyOf ( const String & charactersToLookFor,
int startIndex = 0,
bool ignoreCase = false
) const throw ()
返回与给出的字符串中的任意一个字符相匹配的字符的索引位置。

此函数从索引为startIndex的位置开始向后搜索,如果找到charactersToLookFor字符串中的任意一个字符,则立即返回其索引位置。

如果没有找到,则返回-1。

如果ignoreCase为true,则不区分大小写。

参见:
indexOfChar, lastIndexOfAnyOf
int String::indexOf ( const String & text ) const throw ()
在该字符串中搜索给出的子字符串。

此方法区分大小写。

返回:
参数字符串首次出现的索引位置。如果没找到,则返回-1。

1 Like

int String::indexOf ( int startIndex,
const String & textToLookFor
) const throw ()
在该字符串中搜索给出的子字符串。

此方法区分大小写。

参数:
startIndex 从该位置起向后搜索
textToLookFor 要搜索的字符串
返回:
参数字符串首次出现的索引位置。如果没找到,则返回-1。
int String::indexOfIgnoreCase ( const String & textToLookFor ) const throw ()
在该字符串中搜索给出的子字符串。

此方法不区分大小写。

返回:
参数字符串首次出现的索引位置。如果没找到,则返回-1。
int String::indexOfIgnoreCase ( int startIndex,
const String & textToLookFor
) const throw ()
在该字符串中搜索给出的子字符串。

此方法不区分大小写。

参数:
startIndex 从该位置起向后搜索
textToLookFor 要搜索的字符串
返回:
参数字符串首次出现的索引位置。如果没找到,则返回-1。
int String::lastIndexOfChar ( juce_wchar character ) const throw ()
在该字符串中搜索给出的字符(由后向前查找)。

此方法区分大小写。

返回:
参数字符在该字符串中最后出现的索引位置。如果没找到,则返回-1。
int String::lastIndexOf ( const String & textToLookFor ) const throw ()
在该字符串中搜索给出的字符串(由后向前查找)。

此方法区分大小写。

返回:
参数字符串最后一次出现在该字符串的位置(以参数字符串的第一个字符为基准)。如果没找到,则返回-1。
int String::lastIndexOfIgnoreCase ( const String & textToLookFor ) const throw ()
在该字符串中搜索给出的字符串(由后向前查找)。

此方法不区分大小写。

返回:
参数字符串最后一次出现在该字符串的位置(以参数字符串的第一个字符为基准)。如果没找到,则返回-1。
int String::lastIndexOfAnyOf ( const String & charactersToLookFor,
bool ignoreCase = false
) const throw ()
由后至前搜索,如果找到给定字符串的任意一个字符,则返回该字符所在的索引位置。

此函数将由后至前进行搜索,如果找到字符串charactersToLookFor中的任意一个字符,则返回其所在的索引位置。

如果没有找到,则返回-1。

如果ignoreCase为true,则不区分大小写。

参见:
lastIndexOf, indexOfAnyOf
const juce_wchar& String::operator[] ( int index ) const throw ()
按索引值返回该字符串的某个字符。

此函数不进行越界检查,因此要特别小心!

引用:isPositiveAndNotGreaterThan(), 和jassert。

juce_wchar& String::operator[] ( int index )
返回字符串中的某个字符,此方法也可以直接给该字符赋值,以改变之。

如果打算更改字符串中的某个特定字符,使用此函数将比较方便。

注意:索引值不进行越界校验,因此要特别小心!

juce_wchar String::getLastCharacter ( ) const throw ()
返回字符串的最后一个字符。

如果该字符串为空,则返回0。

const String String::substring ( int startIndex,
int endIndex
) const
提取字符串的部分内容。

如果给出的范围超出字符串的实际大小,则尽可能多的返回所需的内容。

参数:
startIndex 从此处开始提取
endIndex 提取到此处(不含此处)
参见:
fromFirstOccurrenceOf, dropLastCharacters, getLastCharacters, upToFirstOccurrenceOf
const String String::substring ( int startIndex ) const
提取字符串的后半部分。

参数:
startIndex 从此处开始提取,包含第一个字符。如果该值越界,则返回空字符串。如果小于等于0,则返回整个字符串。
返回:
由startIndex开始到该字符串结尾的所有内容。
参见:
dropLastCharacters, getLastCharacters, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf
const String String::dropLastCharacters ( int numberToDrop ) const
返回去掉最后几个字符的该字符串。

参数:
numberToDrop 删除该字符串末尾的几个字符如果该值越界,则返回一个空字符串。小于等于0,则返回完整的该字符串。
参见:
substring, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf, getLastCharacter
const String String::getLastCharacters ( int numCharacters ) const
返回该字符串最后的部分,返回几个字符由给出的参数确定。

返回该字符串末尾的numCharacters个字符。如果参数numCharacters超过字符串的大小,则返回整个字符串。

参见:
substring, dropLastCharacters, getLastCharacter
const String String::fromFirstOccurrenceOf ( const String & substringToStartFrom,
bool includeSubStringInResult,
bool ignoreCase
) const
返回由给定的子字符串为开始的后半部分内容。

此函数将搜索给定字符串,如果找到,则返回参数字符串所处位置到该字符串最后的部分,返回的结果可设置是否包含参数字符串本身。

比如:一个字符串为"123456",fromFirstOccurrenceOf (“34”, true) 将返回"3456",fromFirstOccurrenceOf (“34”, false) 将返回"56"。

如果没找到,则返回空字符串。

如果ignoreCase为true,则不区分大小写。

参见:
upToFirstOccurrenceOf, fromLastOccurrenceOf
const String String::fromLastOccurrenceOf ( const String & substringToFind,
bool includeSubStringInResult,
bool ignoreCase
) const
返回由给定的子字符串为结尾的一部分内容。

此函数类似于fromFirstOccurrenceOf(),所不同的是由后至前搜索给定的字符串,并且在没有找到的情况下返回整个字符串。

参见:
fromFirstOccurrenceOf, upToLastOccurrenceOf
const String String::upToFirstOccurrenceOf ( const String & substringToEndWith,
bool includeSubStringInResult,
bool ignoreCase
) const
返回此字符串开头的一部分,直至遇到给出的字符串。

此函数从前到后搜索给定的字符串,如果找到,则返回从开始到找到点的内容。可以设置返回结果是否包含给出的字符串。。

比如:字符串"123456",upTo (“34”, false)将返回"12",upTo (“34”, true)将返回"1234"。

如果没找到,则返回整个字符串。

参见:
upToLastOccurrenceOf, fromFirstOccurrenceOf
const String String::upToLastOccurrenceOf ( const String & substringToFind,
bool includeSubStringInResult,
bool ignoreCase
) const
返回此字符串开头的一部分,直至给出的字符串不再出现。

此函数类似于upToFirstOccurrenceOf(),所不同的是,一直搜到给出的字符串所出现的最后位置,而后返回该字符串从最开头到找到点的内容。如果没找到,则返回整个字符串。

参见:
upToFirstOccurrenceOf, fromFirstOccurrenceOf
const String String::trim ( ) const
删除开头和末尾的空格字符,而后返回。

引用给:Rectangle< int >::fromString()。

const String String::trimStart ( ) const
删除开头的空格字符,而后返回。

const String String::trimEnd ( ) const
删除末尾的空格字符,而后返回。

const String String::trimCharactersAtStart ( const String & charactersToTrim ) const
从开始处删除给定的字符串,而后返回。

该函数相当于将给定的字符串从该字符串中全部移除。采用从前到后的搜索方式。

参数:
charactersToTrim 要删除的字符串。
参见:
trim, trimStart, trimCharactersAtEnd
const String String::trimCharactersAtEnd ( const String & charactersToTrim ) const
由后往前删除给定的字符串,而后返回。

该函数相当于将给定的字符串从该字符串中全部移除。采用由后至前的搜索方式。

参数:
charactersToTrim 要删除的字符串。
参见:
trim, trimEnd, trimCharactersAtStart
const String String::toUpperCase ( ) const
返回此字符串的大写版本。

const String String::toLowerCase ( ) const
返回此字符串的小写版本。

const String String::replaceSection ( int startIndex,
int numCharactersToReplace,
const String & stringToInsert
) const
用另一个字符串替换该字符串的一部分内容。

从startIndex处到startIndex + numCharsToReplace处的内容将被移除,并在该区域内插入一个新的字符串。

注意,这是一个const方法,并不改变字符串本身。

参数:
startIndex 要移除的第一个字符所在的位置。如果该值越界,将强制到可用范围。
numCharactersToReplace 要移除的字符数。小于等于0,则不移除任何字符。
stringToInsert 要插入的新字符串。
const String String::replace ( const String & stringToReplace,
const String & stringToInsertInstead,
bool ignoreCase = false
) const
用另一个字符串替换本字符串。

此函数相当于交换两个参数字符串的值,而后返回包含交换结果的整个字符串。

注意,这是一个const方法,并不改变字符串本身。

const String String::replaceCharacter ( juce_wchar characterToReplace,
juce_wchar characterToInsertInstead
) const
替换该字符串的某个字符。

const String String::replaceCharacters ( const String & charactersToReplace,
const String & charactersToInsertInstead
) const
替换该字符串中的某些字符。

两个参数字符串必须长度一致,第二个参数的内容替换第一个参数的内容。

比如:replaceCharacters (“abc”, “def”) ,结果为:‘a’为’d’、'b’为’e’等等。

注意,这是一个const方法,并不改变字符串本身。

const String String::retainCharacters ( const String & charactersToRetain ) const
仅保留参数字符串所包含的字符。

返回字符串的副本,移除参数字符串中所没有的任何字符。

比如:“1122334455”, retainCharacters (“432”)将返回"223344"。

注意,这是一个const方法,并不改变字符串本身。

const String String::removeCharacters ( const String & charactersToRemove ) const
移除某些字符。

返回字符串的副本,保留参数字符串中所没有的字符。

比如:“1122334455”, removeCharacters (“432”) 将返回"1155"。

注意,这是一个const方法,并不改变字符串本身。

const String String::initialSectionContainingOnly ( const String & permittedCharacters ) const
从该字符串的开头处返回不包含特定字符集合的内容。

此方法返回该字符串的前半部分,直至遇到参数字符串中所没有的第一个字符。

const String String::initialSectionNotContaining ( const String & charactersToStopAt ) const
从该字符串的开头处返回不包含特定字符集合的内容。

此方法返回该字符串的前半部分,直至遇到参数字符串所包含的某个字符。

bool String::isQuotedString ( ) const
检查该字符串是否以引号开头。

返回:
如果字符串的开头为单引号或双引号,则返回true。如果引号之前有空格,依然返回true。注意:此函数不检查字符串的末尾字符。
参见:
unquoted, quoted

1 Like

const String String::unquoted ( ) const
如包含引号则删之。

删除该字符串末尾的引号。如果末尾无引号,则此函数不起作用。这种情况下,返回原始字符串。

注意,这是一个const方法,并不改变字符串本身。

参见:
isQuotedString, quoted
const String String::quoted ( juce_wchar quoteCharacter = ‘"’ ) const
前后添加引号。

给该字符串的前后添加双引号,如果已有一个引号,则不添加。所以,针对有引号的字符串使用此函数是安全的,无需担心出现转义错误的问题。

注意,这是一个const方法,并不改变字符串本身。

参数:
quoteCharacter 前后要添加的引号字符。
参见:
isQuotedString, unquoted
static const String String::repeatedString ( const String & stringToRepeat,
int numberOfTimesToRepeat
) [static]
将一个字符串重复多次后形成一个新的字符串。

参数:
stringToRepeat 要重复的字符串
numberOfTimesToRepeat 重复的次数
const String String::paddedLeft ( juce_wchar padCharacter,
int minimumLength
) const
指定的字符重复添加到该字符串的开始处,直到总长度达到所指定的长度。

const String String::paddedRight ( juce_wchar padCharacter,
int minimumLength
) const
指定的字符重复添加到该字符串的结束处,直到总长度达到所指定的长度。

static const String String::createStringFromData ( const void * data,
int size
) [static]
将一个未知格式的数据转换为字符串。

尝试猜测某些二进制数据是否为Unicode或8位的字符,然后返回一个字符串以判断猜测是否无误。

应该能够正确处理Unicode格式的字节顺序,可查看最开头的两个字节。

static const String String::formatted ( const juce_wchar * formatString,

) [static]
以printf样式为参数列表来创建一个字符串。

我个人并不喜欢这个函数。建议尽量不要使用。可用重载的输出运算符<<或者类似的方法来替代。保留它只是为了兼容一部分老代码和个别用户的使用习惯…

如果坚持要使用,则务必不要用任何String对象作为该函数的实参。

int String::getIntValue ( ) const throw ()
将字符串的值转为十进制数字(最多32位大小)。

返回:
32位有符号十进制整数。
参见:
getTrailingIntValue, getHexValue32, getHexValue64
int64 String::getLargeIntValue ( ) const throw ()
将字符串的值转为十进制数字(最多64位大小)。

返回:
64位有符号十进制整数。
int String::getTrailingIntValue ( ) const throw ()
提取字符串结尾的十进制数字。

此函数将尝试读取字符串结尾的数值型字符。比如:"321 xyz654"将返回654。"2 3 4"将返回4。

不处理负数。比如:"xyz-5"将返回5。

参见:
getIntValue
float String::getFloatValue ( ) const throw ()
提取字符串的浮点型数字。

返回:
32位浮点型数值。
参见:
getDoubleValue
double String::getDoubleValue ( ) const throw ()
提取字符串的浮点型数字。

返回:
64位浮点型数值。
参见:
getFloatValue
int String::getHexValue32 ( ) const throw ()
提取字符串的16进制数字。

字符中无十六进制数字时,此函数不起作用。

如果字符串包含了太多的字符,则返回最低位的有效数字。比如:"ffff12345678"将返回0x12345678。

返回:
32位十六进制数值。
int64 String::getHexValue64 ( ) const throw ()
提取字符串的16进制数字。

字符中无十六进制数字时,此函数不起作用。

如果字符串包含了太多的字符,则返回最低位的有效数字。比如"ffff1234567812345678"将返回0x1234567812345678。

返回:
64位十六进制数值。
static const String String::toHexString ( int number ) [static]
创建十进制数字的32位十六进制数字字符串。

static const String String::toHexString ( int64 number ) [static]
创建十进制数字的64位十六进制数字字符串。

static const String String::toHexString ( short number ) [static]
创建十进制数字的16位十六进制数字。

static const String String::toHexString ( const unsigned char * data,
int size,
int groupSize = 1
) [static]
创建一个字符串,其中包含块的二进制数据的十六进制转储。

参数:
data 作为输入的二进制数据
size 使用数据的几个字节
groupSize 几个字节编为一组,输出时各组之间插入一个空格。比如:编组大小为0不输出空格,为1看起来类似余"be a1 c2 ff",为2则类似于"bea1 c2ff"。
String::operator const juce_wchar * ( ) const throw ()
返回此字符串的unicode版本。

该函数返回字符串数据的内部引用,因此无法保存返回的指针,某些String类的函数调用时可能出现无效错误,即使是const类型的函数。

String::operator juce_wchar * ( ) throw ()
返回此字符串的unicode版本。

该函数返回字符串数据的内部引用,因此无法保存返回的指针,某些String类的函数调用时可能出现无效错误,即使是const类型的函数。

const char* String::toUTF8 ( ) const
返回此字符串的UTF-8版本的指针。

该函数返回字符串数据的内部引用,因此无法保存返回的指针,每当字符串发生变化时将被销毁。

参见:
getNumBytesAsUTF8, fromUTF8, copyToUTF8, toCString
引用给:operator<<()。

static const String String::fromUTF8 ( const char * utf8buffer,
int bufferSizeBytes = -1
) [static]
从UTF-8编码的缓冲区中创建一个String。

如果大小小于0,则持续读取,直至遇到0值。

int String::getNumBytesAsUTF8 ( ) const throw ()
返回此字符串表示UTF8格式所需的字节数。

返回值不包含结尾的0值。

参见:
toUTF8, copyToUTF8
int String::copyToUTF8 ( char * destBuffer,
int maxBufferSizeBytes
) const throw ()
将字符串作为UTF-8字符复制到缓冲区中。

返回缓冲区副本的字节数,包括结束处的空字符。

参数:
destBuffer 存储复制数据的空间。如果为空指针,此函数将返回所需的字节数,包括结束处的空字符。
maxBufferSizeBytes 目标缓冲区的字节数。如果该字串不匹配,依然可以使末尾为空字符,并返回实际使用的字节数。
const char* String::toCString ( ) const
返回此字符串使用默认的8位多字节系统编码的版本。

该函数返回字符串数据的内部引用,因此无法保存返回的指针,每当字符串发生变化时将被销毁。

参见:
getNumBytesAsCString, copyToCString, toUTF8
int String::getNumBytesAsCString ( ) const throw ()
返回此字符串的字节数。

int String::copyToCString ( char * destBuffer,
int maxBufferSizeBytes
) const throw ()
将字符串复制到缓冲区中。

参数:
destBuffer 存储复制数据的空间。如果为空指针,此函数将返回所需的字节数,包括结束处的空字符。
maxBufferSizeBytes 目标缓冲区的字节数。 如果该字串不匹配,依然可以使末尾为空字符,并返回实际使用的字节数。
void String::copyToUnicode ( juce_wchar * destBuffer,
int maxCharsToCopy
) const throw ()
将字符串复制到unicode缓冲区中。

参数:
destBuffer 要复制到的地方
maxCharsToCopy 最大字节数将复制到缓冲区,不包含结尾的空字符0,因此该值不应该大于(目标缓冲区 - 1)。
void String::preallocateStorage ( size_t numCharsNeeded )
为此字符串增加内部分配的存储区。

调用此函数不会影响字符串的内容,它将为该字符串增加内部分配的内存总数。

如果要使用一个较大的数值,使用 += 或 << 运算符能预先分配足够的空间,从而提供更好的性能。因为这样一来,该函数将无需频繁的调整字符串的大小以追加额外的字符。

参数:
numCharsNeeded 要分配的存储空间。如果该值小于当前已经分配的值,则不起作用。
Referenced by Rectangle< int >::toString().

void String::swapWith ( String & other ) throw ()
交换两个字符串的内容。

这是一个非常快速的操作,无需分配或复制任何数据。

成员数据文档

const String String::empty [static]
清空字符串的内容,使之变成空字符串。

此方法优于String(),效率更高。

引用给:Rectangle< int >::fromString()。

定义该类的头文件:
juce_String.h

[size=150]MidiMessage MIDI消息类[/size]

封装一条MIDI消息。 更多…

所有成员

Public类型

enum SmpteTimecodeType { fps24 = 0, fps25 = 1, fps30drop = 2, fps30 = 3 }

SMPTE时间码类型。

更多…
enum MidiMachineControlCommand {
mmc_stop = 1, mmc_play = 2, mmc_deferredplay = 3, mmc_fastforward = 4,
mmc_rewind = 5, mmc_recordStart = 6, mmc_recordStop = 7, mmc_pause = 9
}

MMC命令类型。

更多…

Public成员函数

MidiMessage (int byte1, int byte2, int byte3, double timeStamp=0) throw ()
创建一条3字节的短MIDI消息。 
MidiMessage (int byte1, int byte2, double timeStamp=0) throw ()
创建一条2字节的短MIDI消息。 
MidiMessage (int byte1, double timeStamp=0) throw ()
创建一条单字节的MIDI消息。 
MidiMessage (const void *data, int numBytes, double timeStamp=0)
从数据块中创建一条MIDI消息。 
MidiMessage (const void *data, int maxBytesToUse, int &numBytesUsed, uint8 lastStatusByte, double timeStamp=0)
从某些数据中读取下一条MIDI消息。 
MidiMessage (const MidiMessage &other)
创建另一条MIDI消息的副本(拷贝构造函数)。 
MidiMessage (const MidiMessage &other, double newTimeStamp)
创建另一条MIDI消息,具有不同的时戳。 
~MidiMessage ()
 析构函数。 

MidiMessage & operator= (const MidiMessage &other)
赋值运算符重载。
uint8 * getRawData () const throw ()
返回一个指向原始MIDI数据的指针。
int getRawDataSize () const throw ()
返回消息中的数据的字节数。
double getTimeStamp () const throw ()
返回消息的相关时戳。
void setTimeStamp (double newTimestamp) throw ()
改变消息的相关时戳。
void addToTimeStamp (double delta) throw ()
将一个值添加给消息时戳。
int getChannel () const throw ()
返回消息的相关MIDI通道。
bool isForChannel (int channelNumber) const throw ()
如果消息应用到给定的MIDI通道,则返回true。
void setChannel (int newChannelNumber) throw ()
改变消息的MIDI通道。
bool isSysEx () const throw ()
如果是系统专用消息,则返回true。
const uint8 * getSysExData () const throw ()
返回消息中包含的系统专用数据的指针。
int getSysExDataSize () const throw ()
返回系统专用数据的大小。
bool isNoteOn (bool returnTrueForVelocity0=false) const throw ()
如果消息为“键按下”事件,则返回true。
bool isNoteOff (bool returnTrueForNoteOnVelocity0=true) const throw ()
如果消息为“键抬起”事件。则返回true。
bool isNoteOnOrOff () const throw ()
如果消息为“键按下”或“键抬起”事件,则返回true。
int getNoteNumber () const throw ()
返回音符开和音符关消息的MIDI音符编号。
void setNoteNumber (int newNoteNumber) throw ()
改变音符开或音符关消息的MIDI音符编号。
uint8 getVelocity () const throw ()
返回音符开或音符关消息的力度。
float getFloatVelocity () const throw ()
返回音符开或音符关消息的力度。
void setVelocity (float newVelocity) throw ()
改变音符开或音符关消息的力度。
void multiplyVelocity (float scaleFactor) throw ()
以给定的参数值“缩放”音符开或音符关MIDI消息的力度(乘以参数值)。
bool isProgramChange () const throw ()
如果消息为程序(音色)改变消息,则返回true。
int getProgramChangeNumber () const throw ()
返回音色改变的程序编号。
bool isPitchWheel () const throw ()
如果消息为弯音轮变化,则返回true。
int getPitchWheelValue () const throw ()
从弯音变化消息中返回弯音的位置。
bool isAftertouch () const throw ()
如果消息为一个触后事件,则返回true。
int getAfterTouchValue () const throw ()
返回触后消息中的触后总量。
bool isChannelPressure () const throw ()
如果消息为通道压力改变事件,则返回true。
int getChannelPressureValue () const throw ()
返回通道压力改变消息中的压力数值。
bool isController () const throw ()
如果为MIDI控制器消息,则返回true。
int getControllerNumber () const throw ()
返回控制器消息的控制编号。
int getControllerValue () const throw ()
返回控制器消息的控制编号。
bool isAllNotesOff () const throw ()
检测此消息是否为所有音符关闭消息
bool isAllSoundOff () const throw ()
检测此消息是否为所有声音关闭消息。
bool isMetaEvent () const throw ()
如果此事件为元事件,则返回true。
int getMetaEventType () const throw ()
返回元事件的类型编号。
const uint8 * getMetaEventData () const throw ()
返回一个指针,其指向元事件中的数据。
int getMetaEventLength () const throw ()
返回元事件中的数据的长度。
bool isTrackMetaEvent () const throw ()
如果是一个“音轨”元事件,则返回true。
bool isEndOfTrackMetaEvent () const throw ()
如果该消息为“end-of-track(音轨结束)”元事件,则返回true。
bool isTrackNameEvent () const throw ()
如果该消息为“音轨名称”元事件,则返回true。
bool isTextMetaEvent () const throw ()
如果该消息为“文本”元事件,则返回true。
const String getTextFromTextMetaEvent () const
返回文本元事件的文本内容。
bool isTempoMetaEvent () const throw ()
如果该消息为“速度”元事件,则返回true。
double getTempoMetaEventTickLength (short timeFormat) const throw ()
返回速度元事件的嘀嗒长度。

double getTempoSecondsPerQuarterNote () const throw ()
计算速度元事件每个四分音符的秒数。
bool isTimeSignatureMetaEvent () const throw ()
如果该消息为“拍号”元事件,则返回true。
void getTimeSignatureInfo (int &numerator, int &denominator) const throw ()
返回拍号元事件的拍号。
bool isKeySignatureMetaEvent () const throw ()
如果该消息为“调号”元事件,则返回true。
int getKeySignatureNumberOfSharpsOrFlats () const throw ()
返回调号元事件的调号。
bool isMidiChannelMetaEvent () const throw ()
如果该消息为“通道”元事件,则返回true。
int getMidiChannelMetaEventChannel () const throw ()
返回通道元事件的通道编号。
bool isActiveSense () const throw ()
如果为“激活”消息,则返回true。
bool isMidiStart () const throw ()
如果为MIDI开始事件,则返回true。
bool isMidiContinue () const throw ()
如果为MIDI继续事件,则返回true。
bool isMidiStop () const throw ()
如果为MIDI停止事件,则返回true。
bool isMidiClock () const throw ()
如果为MIDI时钟事件,则返回true。
bool isSongPositionPointer () const throw ()
如果该消息为“乐曲位置指针”,则返回true。
int getSongPositionPointerMidiBeat () const throw ()
返回“乐曲位置指针”为第几拍的MIDI消息。
bool isQuarterFrame () const throw ()
如果为“四分音符框架”MIDI时间码消息,则返回true。
int getQuarterFrameSequenceNumber () const throw ()
返回MIDI时间码消息的序号。
int getQuarterFrameValue () const throw ()
返回“四分音符框架”消息的值。
bool isFullFrame () const throw ()
如果为“全音符框架”MIDI时间码消息,则返回true。
void getFullFrameParameters (int &hours, int &minutes, int &seconds, int &frames, SmpteTimecodeType &timecodeType) const throw ()
从“全音符框架”MIDI时间码消息中提取时间码信息。
bool isMidiMachineControlMessage () const throw ()
检测是否为一个MMC消息。
MidiMachineControlCommand getMidiMachineControlCommand () const throw ()
返回MMC消息的类型。
bool isMidiMachineControlGoto (int &hours, int &minutes, int &seconds, int &frames) const throw ()
检测是否为MMC跳转(goto)消息。