LMMS
Loading...
Searching...
No Matches
juce::CodeEditorComponent Class Reference

#include <juce_CodeEditorComponent.h>

Inheritance diagram for juce::CodeEditorComponent:
juce::Component juce::ApplicationCommandTarget juce::TextInputTarget juce::MouseListener

Classes

struct  State
struct  ColourScheme
class  CodeEditorAccessibilityHandler
class  CodeEditorLine
class  Pimpl
class  GutterComponent

Public Types

enum  ColourIds {
  backgroundColourId = 0x1004500 , highlightColourId = 0x1004502 , defaultTextColourId = 0x1004503 , lineNumberBackgroundId = 0x1004504 ,
  lineNumberTextId = 0x1004505
}
Public Types inherited from juce::Component
enum class  FocusContainerType { none , focusContainer , keyboardFocusContainer }
enum  FocusChangeType { focusChangedByMouseClick , focusChangedByTabKey , focusChangedDirectly }
Public Types inherited from juce::TextInputTarget
enum  VirtualKeyboardType {
  textKeyboard = 0 , numericKeyboard , decimalKeyboard , urlKeyboard ,
  emailAddressKeyboard , phoneNumberKeyboard
}

Public Member Functions

 CodeEditorComponent (CodeDocument &document, CodeTokeniser *codeTokeniser)
 ~CodeEditorComponent () override
CodeDocumentgetDocument () const noexcept
void loadContent (const String &newContent)
float getCharWidth () const noexcept
int getLineHeight () const noexcept
int getNumLinesOnScreen () const noexcept
int getFirstLineOnScreen () const noexcept
int getNumColumnsOnScreen () const noexcept
CodeDocument::Position getCaretPos () const
Rectangle< intgetCaretRectangle () override
void moveCaretTo (const CodeDocument::Position &newPos, bool selecting)
Rectangle< intgetCharacterBounds (const CodeDocument::Position &pos) const
CodeDocument::Position getPositionAt (int x, int y) const
CodeDocument::Position getSelectionStart () const
CodeDocument::Position getSelectionEnd () const
void setLineNumbersShown (bool shouldBeShown)
bool moveCaretLeft (bool moveInWholeWordSteps, bool selecting)
bool moveCaretRight (bool moveInWholeWordSteps, bool selecting)
bool moveCaretUp (bool selecting)
bool moveCaretDown (bool selecting)
bool scrollDown ()
bool scrollUp ()
bool pageUp (bool selecting)
bool pageDown (bool selecting)
bool moveCaretToTop (bool selecting)
bool moveCaretToStartOfLine (bool selecting)
bool moveCaretToEnd (bool selecting)
bool moveCaretToEndOfLine (bool selecting)
bool deleteBackwards (bool moveInWholeWordSteps)
bool deleteForwards (bool moveInWholeWordSteps)
bool deleteWhitespaceBackwardsToTabStop ()
virtual bool copyToClipboard ()
virtual bool cutToClipboard ()
virtual bool pasteFromClipboard ()
bool undo ()
bool redo ()
void selectRegion (const CodeDocument::Position &start, const CodeDocument::Position &end)
bool selectAll ()
void deselectAll ()
void scrollToLine (int newFirstLineOnScreen)
void scrollBy (int deltaLines)
void scrollToColumn (int newFirstColumnOnScreen)
void scrollToKeepCaretOnScreen ()
void scrollToKeepLinesOnScreen (Range< int > linesToShow)
void insertTextAtCaret (const String &textToInsert) override
void insertTabAtCaret ()
void indentSelection ()
void unindentSelection ()
Range< intgetHighlightedRegion () const override
bool isHighlightActive () const noexcept
void setHighlightedRegion (const Range< int > &newRange) override
String getTextInRange (const Range< int > &range) const override
void setTabSize (int numSpacesPerTab, bool insertSpacesInsteadOfTabCharacters)
int getTabSize () const noexcept
bool areSpacesInsertedForTabs () const
String getTabString (int numSpaces) const
void setFont (const Font &newFont)
const FontgetFont () const noexcept
void setReadOnly (bool shouldBeReadOnly) noexcept
bool isReadOnly () const noexcept
void setColourScheme (const ColourScheme &scheme)
const ColourSchemegetColourScheme () const noexcept
Colour getColourForTokenType (int tokenType) const
void retokenise (int startIndex, int endIndex)
void setScrollbarThickness (int thickness)
int getScrollbarThickness () const noexcept
virtual void handleReturnKey ()
virtual void handleTabKey ()
virtual void handleEscapeKey ()
virtual void editorViewportPositionChanged ()
virtual void caretPositionMoved ()
virtual void addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEvent *mouseClickEvent)
virtual void performPopupMenuAction (int menuItemID)
void setCommandManager (ApplicationCommandManager *newManager) noexcept
void paint (Graphics &) override
void resized () override
bool keyPressed (const KeyPress &) override
void mouseDown (const MouseEvent &) override
void mouseDrag (const MouseEvent &) override
void mouseUp (const MouseEvent &) override
void mouseDoubleClick (const MouseEvent &) override
void mouseWheelMove (const MouseEvent &, const MouseWheelDetails &) override
void focusGained (FocusChangeType) override
void focusLost (FocusChangeType) override
bool isTextInputActive () const override
void setTemporaryUnderlining (const Array< Range< int > > &) override
ApplicationCommandTargetgetNextCommandTarget () override
void getAllCommands (Array< CommandID > &) override
void getCommandInfo (CommandID, ApplicationCommandInfo &) override
bool perform (const InvocationInfo &) override
void lookAndFeelChanged () override
Public Member Functions inherited from juce::Component
 Component () noexcept
 ~Component () override
 Component (const String &componentName) noexcept
String getName () const noexcept
virtual void setName (const String &newName)
String getComponentID () const noexcept
void setComponentID (const String &newID)
virtual void setVisible (bool shouldBeVisible)
bool isVisible () const noexcept
virtual void visibilityChanged ()
bool isShowing () const
virtual void addToDesktop (int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
void removeFromDesktop ()
bool isOnDesktop () const noexcept
ComponentPeergetPeer () const
virtual void userTriedToCloseWindow ()
virtual void minimisationStateChanged (bool isNowMinimised)
virtual float getDesktopScaleFactor () const
void toFront (bool shouldAlsoGainKeyboardFocus)
void toBack ()
void toBehind (Component *other)
void setAlwaysOnTop (bool shouldStayOnTop)
bool isAlwaysOnTop () const noexcept
int getX () const noexcept
int getY () const noexcept
int getWidth () const noexcept
int getHeight () const noexcept
int getRight () const noexcept
Point< intgetPosition () const noexcept
int getBottom () const noexcept
Rectangle< intgetBounds () const noexcept
Rectangle< intgetLocalBounds () const noexcept
Rectangle< intgetBoundsInParent () const noexcept
int getScreenX () const
int getScreenY () const
Point< intgetScreenPosition () const
Rectangle< intgetScreenBounds () const
Point< intgetLocalPoint (const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
Point< float > getLocalPoint (const Component *sourceComponent, Point< float > pointRelativeToSourceComponent) const
Rectangle< intgetLocalArea (const Component *sourceComponent, Rectangle< int > areaRelativeToSourceComponent) const
Rectangle< float > getLocalArea (const Component *sourceComponent, Rectangle< float > areaRelativeToSourceComponent) const
Point< intlocalPointToGlobal (Point< int > localPoint) const
Point< float > localPointToGlobal (Point< float > localPoint) const
Rectangle< intlocalAreaToGlobal (Rectangle< int > localArea) const
Rectangle< float > localAreaToGlobal (Rectangle< float > localArea) const
void setTopLeftPosition (int x, int y)
void setTopLeftPosition (Point< int > newTopLeftPosition)
void setTopRightPosition (int x, int y)
void setSize (int newWidth, int newHeight)
void setBounds (int x, int y, int width, int height)
void setBounds (Rectangle< int > newBounds)
void setBoundsRelative (float proportionalX, float proportionalY, float proportionalWidth, float proportionalHeight)
void setBoundsRelative (Rectangle< float > proportionalArea)
void setBoundsInset (BorderSize< int > borders)
void setBoundsToFit (Rectangle< int > targetArea, Justification justification, bool onlyReduceInSize)
void setCentrePosition (int x, int y)
void setCentrePosition (Point< int > newCentrePosition)
void setCentreRelative (float x, float y)
void centreWithSize (int width, int height)
void setTransform (const AffineTransform &transform)
AffineTransform getTransform () const
bool isTransformed () const noexcept
int proportionOfWidth (float proportion) const noexcept
int proportionOfHeight (float proportion) const noexcept
int getParentWidth () const noexcept
int getParentHeight () const noexcept
Rectangle< intgetParentMonitorArea () const
int getNumChildComponents () const noexcept
ComponentgetChildComponent (int index) const noexcept
int getIndexOfChildComponent (const Component *child) const noexcept
const Array< Component * > & getChildren () const noexcept
ComponentfindChildWithID (StringRef componentID) const noexcept
void addChildComponent (Component *child, int zOrder=-1)
void addChildComponent (Component &child, int zOrder=-1)
void addAndMakeVisible (Component *child, int zOrder=-1)
void addAndMakeVisible (Component &child, int zOrder=-1)
void addChildAndSetID (Component *child, const String &componentID)
void removeChildComponent (Component *childToRemove)
ComponentremoveChildComponent (int childIndexToRemove)
void removeAllChildren ()
void deleteAllChildren ()
ComponentgetParentComponent () const noexcept
template<class TargetClass>
TargetClass * findParentComponentOfClass () const
ComponentgetTopLevelComponent () const noexcept
bool isParentOf (const Component *possibleChild) const noexcept
virtual void parentHierarchyChanged ()
virtual void childrenChanged ()
virtual bool hitTest (int x, int y)
void setInterceptsMouseClicks (bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
void getInterceptsMouseClicks (bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const noexcept
bool contains (Point< int > localPoint)
bool contains (Point< float > localPoint)
bool reallyContains (Point< int > localPoint, bool returnTrueIfWithinAChild)
bool reallyContains (Point< float > localPoint, bool returnTrueIfWithinAChild)
ComponentgetComponentAt (int x, int y)
ComponentgetComponentAt (Point< int > position)
ComponentgetComponentAt (Point< float > position)
void repaint ()
void repaint (int x, int y, int width, int height)
void repaint (Rectangle< int > area)
void setBufferedToImage (bool shouldBeBuffered)
Image createComponentSnapshot (Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
void paintEntireComponent (Graphics &context, bool ignoreAlphaLevel)
void setPaintingIsUnclipped (bool shouldPaintWithoutClipping) noexcept
bool isPaintingUnclipped () const noexcept
void setComponentEffect (ImageEffectFilter *newEffect)
ImageEffectFiltergetComponentEffect () const noexcept
LookAndFeelgetLookAndFeel () const noexcept
void setLookAndFeel (LookAndFeel *newLookAndFeel)
void sendLookAndFeelChange ()
void setOpaque (bool shouldBeOpaque)
bool isOpaque () const noexcept
void setBroughtToFrontOnMouseClick (bool shouldBeBroughtToFront) noexcept
bool isBroughtToFrontOnMouseClick () const noexcept
void setExplicitFocusOrder (int newFocusOrderIndex)
int getExplicitFocusOrder () const
void setFocusContainerType (FocusContainerType containerType) noexcept
bool isFocusContainer () const noexcept
bool isKeyboardFocusContainer () const noexcept
ComponentfindFocusContainer () const
ComponentfindKeyboardFocusContainer () const
void setWantsKeyboardFocus (bool wantsFocus) noexcept
bool getWantsKeyboardFocus () const noexcept
void setMouseClickGrabsKeyboardFocus (bool shouldGrabFocus)
bool getMouseClickGrabsKeyboardFocus () const noexcept
void grabKeyboardFocus ()
void giveAwayKeyboardFocus ()
bool hasKeyboardFocus (bool trueIfChildIsFocused) const
void moveKeyboardFocusToSibling (bool moveToNext)
virtual std::unique_ptr< ComponentTraversercreateFocusTraverser ()
virtual std::unique_ptr< ComponentTraversercreateKeyboardFocusTraverser ()
void setHasFocusOutline (bool hasFocusOutline) noexcept
bool hasFocusOutline () const noexcept
bool isEnabled () const noexcept
void setEnabled (bool shouldBeEnabled)
virtual void enablementChanged ()
float getAlpha () const noexcept
void setAlpha (float newAlpha)
virtual void alphaChanged ()
void setMouseCursor (const MouseCursor &cursorType)
virtual MouseCursor getMouseCursor ()
void updateMouseCursor () const
virtual void paintOverChildren (Graphics &g)
void mouseMove (const MouseEvent &event) override
void mouseEnter (const MouseEvent &event) override
void mouseExit (const MouseEvent &event) override
void mouseDown (const MouseEvent &event) override
void mouseDrag (const MouseEvent &event) override
void mouseUp (const MouseEvent &event) override
void mouseDoubleClick (const MouseEvent &event) override
void mouseWheelMove (const MouseEvent &event, const MouseWheelDetails &wheel) override
void mouseMagnify (const MouseEvent &event, float scaleFactor) override
void setRepaintsOnMouseActivity (bool shouldRepaint) noexcept
void addMouseListener (MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
void removeMouseListener (MouseListener *listenerToRemove)
void addKeyListener (KeyListener *newListener)
void removeKeyListener (KeyListener *listenerToRemove)
virtual bool keyStateChanged (bool isKeyDown)
virtual void modifierKeysChanged (const ModifierKeys &modifiers)
virtual void focusOfChildComponentChanged (FocusChangeType cause)
bool isMouseOver (bool includeChildren=false) const
bool isMouseButtonDown (bool includeChildren=false) const
bool isMouseOverOrDragging (bool includeChildren=false) const
Point< intgetMouseXYRelative () const
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)
void enterModalState (bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
void exitModalState (int returnValue)
bool isCurrentlyModal (bool onlyConsiderForemostModalComponent=true) const noexcept
bool isCurrentlyBlockedByAnotherModalComponent () const
virtual bool canModalEventBeSentToComponent (const Component *targetComponent)
virtual void inputAttemptWhenModal ()
NamedValueSetgetProperties () noexcept
const NamedValueSetgetProperties () const noexcept
Colour findColour (int colourID, bool inheritFromParent=false) const
void setColour (int colourID, Colour newColour)
void removeColour (int colourID)
bool isColourSpecified (int colourID) const
void copyAllExplicitColoursTo (Component &target) const
virtual void colourChanged ()
voidgetWindowHandle () const
PositionergetPositioner () const noexcept
void setPositioner (Positioner *newPositioner)
void setCachedComponentImage (CachedComponentImage *newCachedImage)
CachedComponentImagegetCachedComponentImage () const noexcept
void setViewportIgnoreDragFlag (bool ignoreDrag) noexcept
bool getViewportIgnoreDragFlag () const noexcept
String getTitle () const noexcept
void setTitle (const String &newTitle)
String getDescription () const noexcept
void setDescription (const String &newDescription)
String getHelpText () const noexcept
void setHelpText (const String &newHelpText)
void setAccessible (bool shouldBeAccessible)
bool isAccessible () const noexcept
AccessibilityHandlergetAccessibilityHandler ()
void invalidateAccessibilityHandler ()
void setFocusContainer (bool shouldBeFocusContainer) noexcept
void contains (int, int)=delete
Public Member Functions inherited from juce::MouseListener
virtual ~MouseListener ()=default
Public Member Functions inherited from juce::ApplicationCommandTarget
 ApplicationCommandTarget ()
virtual ~ApplicationCommandTarget ()
bool invoke (const InvocationInfo &invocationInfo, const bool asynchronously)
bool invokeDirectly (const CommandID commandID, const bool asynchronously)
ApplicationCommandTargetgetTargetForCommand (const CommandID commandID)
bool isCommandActive (const CommandID commandID)
ApplicationCommandTargetfindFirstTargetParentComponent ()
Public Member Functions inherited from juce::TextInputTarget
 TextInputTarget ()=default
virtual ~TextInputTarget ()=default
virtual VirtualKeyboardType getKeyboardType ()

Private Types

enum  DragType { notDragging , draggingSelectionStart , draggingSelectionEnd }

Private Member Functions

void rebuildLineTokens ()
void rebuildLineTokensAsync ()
void codeDocumentChanged (int start, int end)
void clearCachedIterators (int firstLineToBeInvalid)
void updateCachedIterators (int maxLineNum)
void getIteratorForPosition (int position, CodeDocument::Iterator &)
void moveLineDelta (int delta, bool selecting)
int getGutterSize () const noexcept
std::unique_ptr< AccessibilityHandlercreateAccessibilityHandler () override
void insertText (const String &)
virtual void updateCaretPosition ()
void updateScrollBars ()
void scrollToLineInternal (int line)
void scrollToColumnInternal (double column)
void newTransaction ()
void cut ()
void indentSelectedLines (int spacesToAdd)
bool skipBackwardsToPreviousTab ()
bool performCommand (CommandID)
void setSelection (CodeDocument::Position, CodeDocument::Position)
int indexToColumn (int line, int index) const noexcept
int columnToIndex (int line, int column) const noexcept

Private Attributes

CodeDocumentdocument
Font font
int firstLineOnScreen = 0
int spacesPerTab = 4
float charWidth = 0
int lineHeight = 0
int linesOnScreen = 0
int columnsOnScreen = 0
int scrollbarThickness = 16
int columnToTryToMaintain = -1
bool readOnly = false
bool useSpacesForTabs = true
bool showLineNumbers = false
bool shouldFollowDocumentChanges = false
double xOffset = 0
CodeDocument::Position caretPos
CodeDocument::Position selectionStart
CodeDocument::Position selectionEnd
std::unique_ptr< CaretComponentcaret
ScrollBar verticalScrollBar { true }
ScrollBar horizontalScrollBar { false }
ApplicationCommandManagerappCommandManager = nullptr
std::unique_ptr< Pimplpimpl
std::unique_ptr< GutterComponentgutter
DragType dragType = notDragging
CodeTokenisercodeTokeniser
ColourScheme colourScheme
OwnedArray< CodeEditorLinelines
Array< CodeDocument::IteratorcachedIterators

Additional Inherited Members

Static Public Member Functions inherited from juce::Component
static float JUCE_CALLTYPE getApproximateScaleFactorForComponent (const Component *targetComponent)
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent () noexcept
static void JUCE_CALLTYPE unfocusAllComponents ()
static void JUCE_CALLTYPE beginDragAutoRepeat (int millisecondsBetweenCallbacks)
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere () noexcept
static int JUCE_CALLTYPE getNumCurrentlyModalComponents () noexcept
static Component *JUCE_CALLTYPE getCurrentlyModalComponent (int index=0) noexcept
Protected Member Functions inherited from juce::Component
virtual ComponentPeercreateNewPeer (int styleFlags, void *nativeWindowToAttachTo)
Static Protected Member Functions inherited from juce::Component
static std::unique_ptr< AccessibilityHandlercreateIgnoredAccessibilityHandler (Component &)

Detailed Description

A text editor component designed specifically for source code.

This is designed to handle syntax highlighting and fast editing of very large files.

@tags{GUI}

Member Enumeration Documentation

◆ ColourIds

enum juce::CodeEditorComponent::ColourIds

A set of colour IDs to use to change the colour of various aspects of the editor.

These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.

See also
Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
Enumerator
backgroundColourId 

A colour to use to fill the editor's background.

highlightColourId 

The colour to use for the highlighted background under selected text.

defaultTextColourId 

The colour to use for text when no syntax colouring is enabled.

lineNumberBackgroundId 

The colour to use for filling the background of the line-number gutter.

lineNumberTextId 

The colour to use for drawing the line numbers.

◆ DragType

enum juce::CodeEditorComponent::DragType
private
Enumerator
notDragging 
draggingSelectionStart 
draggingSelectionEnd 

Constructor & Destructor Documentation

◆ CodeEditorComponent()

juce::CodeEditorComponent::CodeEditorComponent ( CodeDocument & document,
CodeTokeniser * codeTokeniser )

Creates an editor for a document.

The tokeniser object is optional - pass nullptr to disable syntax highlighting. The object that you pass in is not owned or deleted by the editor - you must make sure that it doesn't get deleted while this component is still using it.

See also
CodeDocument

◆ ~CodeEditorComponent()

juce::CodeEditorComponent::~CodeEditorComponent ( )
override

Destructor.

Member Function Documentation

◆ addPopupMenuItems()

void juce::CodeEditorComponent::addPopupMenuItems ( PopupMenu & menuToAddTo,
const MouseEvent * mouseClickEvent )
virtual

This adds the items to the popup menu.

By default it adds the cut/copy/paste items, but you can override this if you need to replace these with your own items.

If you want to add your own items to the existing ones, you can override this, call the base class's addPopupMenuItems() method, then append your own items.

When the menu has been shown, performPopupMenuAction() will be called to perform the item that the user has chosen.

If this was triggered by a mouse-click, the mouseClickEvent parameter will be a pointer to the info about it, or may be null if the menu is being triggered by some other means.

See also
performPopupMenuAction, setPopupMenuEnabled, isPopupMenuEnabled

◆ areSpacesInsertedForTabs()

bool juce::CodeEditorComponent::areSpacesInsertedForTabs ( ) const
inline

Returns true if the tab key will insert spaces instead of actual tab characters.

See also
setTabSize

◆ caretPositionMoved()

void juce::CodeEditorComponent::caretPositionMoved ( )
virtual

Called when the caret position moves.

◆ clearCachedIterators()

void juce::CodeEditorComponent::clearCachedIterators ( int firstLineToBeInvalid)
private

◆ codeDocumentChanged()

void juce::CodeEditorComponent::codeDocumentChanged ( int start,
int end )
private

◆ columnToIndex()

int juce::CodeEditorComponent::columnToIndex ( int line,
int column ) const
privatenoexcept

◆ copyToClipboard()

bool juce::CodeEditorComponent::copyToClipboard ( )
virtual

◆ createAccessibilityHandler()

std::unique_ptr< AccessibilityHandler > juce::CodeEditorComponent::createAccessibilityHandler ( )
overrideprivatevirtual

Override this method to return a custom AccessibilityHandler for this component.

The default implementation creates and returns a AccessibilityHandler object with an unspecified role, meaning that it will be visible to accessibility clients but without a specific role, action callbacks or interfaces. To control how accessibility clients see and interact with your component subclass AccessibilityHandler, implement the desired behaviours, and return an instance of it from this method in your component subclass.

The accessibility handler you return here is guaranteed to be destroyed before its Component, so it's safe to store and use a reference back to the Component inside the AccessibilityHandler if necessary.

See also
getAccessibilityHandler

Reimplemented from juce::Component.

◆ cut()

void juce::CodeEditorComponent::cut ( )
private

◆ cutToClipboard()

bool juce::CodeEditorComponent::cutToClipboard ( )
virtual

◆ deleteBackwards()

bool juce::CodeEditorComponent::deleteBackwards ( bool moveInWholeWordSteps)

◆ deleteForwards()

bool juce::CodeEditorComponent::deleteForwards ( bool moveInWholeWordSteps)

◆ deleteWhitespaceBackwardsToTabStop()

bool juce::CodeEditorComponent::deleteWhitespaceBackwardsToTabStop ( )

◆ deselectAll()

void juce::CodeEditorComponent::deselectAll ( )

◆ editorViewportPositionChanged()

void juce::CodeEditorComponent::editorViewportPositionChanged ( )
virtual

Called when the view position is scrolled horizontally or vertically.

◆ focusGained()

void juce::CodeEditorComponent::focusGained ( FocusChangeType cause)
overridevirtual

Called to indicate that this component has just acquired the keyboard focus.

See also
focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ focusLost()

void juce::CodeEditorComponent::focusLost ( FocusChangeType cause)
overridevirtual

Called to indicate that this component has just lost the keyboard focus.

See also
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented from juce::Component.

◆ getAllCommands()

void juce::CodeEditorComponent::getAllCommands ( Array< CommandID > & commands)
overridevirtual

This must return a complete list of commands that this target can handle.

Your target should add all the command IDs that it handles to the array that is passed-in.

Implements juce::ApplicationCommandTarget.

◆ getCaretPos()

CodeDocument::Position juce::CodeEditorComponent::getCaretPos ( ) const
inline

Returns the current caret position.

◆ getCaretRectangle()

Rectangle< int > juce::CodeEditorComponent::getCaretRectangle ( )
overridevirtual

Returns the position of the caret, relative to the editor's origin.

Implements juce::TextInputTarget.

◆ getCharacterBounds()

Rectangle< int > juce::CodeEditorComponent::getCharacterBounds ( const CodeDocument::Position & pos) const

Returns the on-screen position of a character in the document. The rectangle returned is relative to this component's top-left origin.

◆ getCharWidth()

float juce::CodeEditorComponent::getCharWidth ( ) const
inlinenoexcept

Returns the standard character width.

◆ getColourForTokenType()

Colour juce::CodeEditorComponent::getColourForTokenType ( int tokenType) const

Returns one the syntax highlighting colour for the given token. The token type values are dependent on the tokeniser being used.

See also
setColourScheme

◆ getColourScheme()

const ColourScheme & juce::CodeEditorComponent::getColourScheme ( ) const
inlinenoexcept

Returns the current syntax highlighting colour scheme.

◆ getCommandInfo()

void juce::CodeEditorComponent::getCommandInfo ( CommandID commandID,
ApplicationCommandInfo & result )
overridevirtual

This must provide details about one of the commands that this target can perform.

This will be called with one of the command IDs that the target provided in its getAllCommands() methods.

It should fill-in all appropriate fields of the ApplicationCommandInfo structure with suitable information about the command. (The commandID field will already have been filled-in by the caller).

The easiest way to set the info is using the ApplicationCommandInfo::setInfo() method to set all the fields at once.

If the command is currently inactive for some reason, this method must use ApplicationCommandInfo::setActive() to make that clear, (or it should set the isDisabled bit of the ApplicationCommandInfo::flags field).

Any default key-presses for the command should be appended to the ApplicationCommandInfo::defaultKeypresses field.

Note that if you change something that affects the status of the commands that would be returned by this method (e.g. something that makes some commands active or inactive), you should call ApplicationCommandManager::commandStatusChanged() to cause the manager to refresh its status.

Implements juce::ApplicationCommandTarget.

◆ getDocument()

CodeDocument & juce::CodeEditorComponent::getDocument ( ) const
inlinenoexcept

Returns the code document that this component is editing.

◆ getFirstLineOnScreen()

int juce::CodeEditorComponent::getFirstLineOnScreen ( ) const
inlinenoexcept

Returns the index of the first line that's visible at the top of the editor.

◆ getFont()

const Font & juce::CodeEditorComponent::getFont ( ) const
inlinenoexcept

Returns the font that the editor is using.

◆ getGutterSize()

int juce::CodeEditorComponent::getGutterSize ( ) const
privatenoexcept

◆ getHighlightedRegion()

Range< int > juce::CodeEditorComponent::getHighlightedRegion ( ) const
overridevirtual

Returns the extents of the selected text region, or an empty range if nothing is selected,

Implements juce::TextInputTarget.

◆ getIteratorForPosition()

void juce::CodeEditorComponent::getIteratorForPosition ( int position,
CodeDocument::Iterator & source )
private

◆ getLineHeight()

int juce::CodeEditorComponent::getLineHeight ( ) const
inlinenoexcept

Returns the height of a line of text, in pixels.

◆ getNextCommandTarget()

ApplicationCommandTarget * juce::CodeEditorComponent::getNextCommandTarget ( )
overridevirtual

This must return the next target to try after this one.

When a command is being sent, and the first target can't handle that command, this method is used to determine the next target that should be tried.

It may return nullptr if it doesn't know of another target.

If your target is a Component, you would usually use the findFirstTargetParentComponent() method to return a parent component that might want to handle it.

See also
invoke

Implements juce::ApplicationCommandTarget.

◆ getNumColumnsOnScreen()

int juce::CodeEditorComponent::getNumColumnsOnScreen ( ) const
inlinenoexcept

Returns the number of whole columns visible on the screen. This doesn't include any cut-off columns at the right-hand edge.

◆ getNumLinesOnScreen()

int juce::CodeEditorComponent::getNumLinesOnScreen ( ) const
inlinenoexcept

Returns the number of whole lines visible on the screen, This doesn't include a cut-off line that might be visible at the bottom if the component's height isn't an exact multiple of the line-height.

◆ getPositionAt()

CodeDocument::Position juce::CodeEditorComponent::getPositionAt ( int x,
int y ) const

Finds the character at a given on-screen position. The coordinates are relative to this component's top-left origin.

◆ getScrollbarThickness()

int juce::CodeEditorComponent::getScrollbarThickness ( ) const
inlinenoexcept

Returns the thickness of the scrollbars.

◆ getSelectionEnd()

CodeDocument::Position juce::CodeEditorComponent::getSelectionEnd ( ) const
inline

Returns the end of the selection as a position.

◆ getSelectionStart()

CodeDocument::Position juce::CodeEditorComponent::getSelectionStart ( ) const
inline

Returns the start of the selection as a position.

◆ getTabSize()

int juce::CodeEditorComponent::getTabSize ( ) const
inlinenoexcept

Returns the current number of spaces per tab.

See also
setTabSize

◆ getTabString()

String juce::CodeEditorComponent::getTabString ( int numSpaces) const

Returns a string containing spaces or tab characters to generate the given number of spaces.

◆ getTextInRange()

String juce::CodeEditorComponent::getTextInRange ( const Range< int > & range) const
overridevirtual

Returns a specified sub-section of the text.

Implements juce::TextInputTarget.

◆ handleEscapeKey()

void juce::CodeEditorComponent::handleEscapeKey ( )
virtual

Called when the escape key is pressed - this can be overridden for custom behaviour.

◆ handleReturnKey()

void juce::CodeEditorComponent::handleReturnKey ( )
virtual

Called when the return key is pressed - this can be overridden for custom behaviour.

◆ handleTabKey()

void juce::CodeEditorComponent::handleTabKey ( )
virtual

Called when the tab key is pressed - this can be overridden for custom behaviour.

◆ indentSelectedLines()

void juce::CodeEditorComponent::indentSelectedLines ( int spacesToAdd)
private

◆ indentSelection()

void juce::CodeEditorComponent::indentSelection ( )

◆ indexToColumn()

int juce::CodeEditorComponent::indexToColumn ( int line,
int index ) const
privatenoexcept

◆ insertTabAtCaret()

void juce::CodeEditorComponent::insertTabAtCaret ( )

◆ insertText()

void juce::CodeEditorComponent::insertText ( const String & newText)
private

◆ insertTextAtCaret()

void juce::CodeEditorComponent::insertTextAtCaret ( const String & textToInsert)
overridevirtual

Inserts some text, overwriting the selected text region, if there is one.

Implements juce::TextInputTarget.

◆ isHighlightActive()

bool juce::CodeEditorComponent::isHighlightActive ( ) const
noexcept

◆ isReadOnly()

bool juce::CodeEditorComponent::isReadOnly ( ) const
inlinenoexcept

Returns true if the editor is set to be read-only.

◆ isTextInputActive()

bool juce::CodeEditorComponent::isTextInputActive ( ) const
overridevirtual

Returns true if this input target is currently accepting input. For example, a text editor might return false if it's in read-only mode.

Implements juce::TextInputTarget.

◆ keyPressed()

bool juce::CodeEditorComponent::keyPressed ( const KeyPress & key)
overridevirtual

Called when a key is pressed.

When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

See also
keyStateChanged, getCurrentlyFocusedComponent, addKeyListener

Reimplemented from juce::Component.

◆ loadContent()

void juce::CodeEditorComponent::loadContent ( const String & newContent)

Loads the given content into the document. This will completely reset the CodeDocument object, clear its undo history, and fill it with this text.

◆ lookAndFeelChanged()

void juce::CodeEditorComponent::lookAndFeelChanged ( )
overridevirtual

Called to let the component react to a change in the look-and-feel setting.

When the look-and-feel is changed for a component, this will be called in all its child components, recursively.

It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.

See also
sendLookAndFeelChange, getLookAndFeel

Reimplemented from juce::Component.

◆ mouseDoubleClick()

void juce::CodeEditorComponent::mouseDoubleClick ( const MouseEvent & event)
overridevirtual

Called when a mouse button has been double-clicked on a component.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp

Reimplemented from juce::MouseListener.

◆ mouseDown()

void juce::CodeEditorComponent::mouseDown ( const MouseEvent & event)
overridevirtual

Called when a mouse button is pressed.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseUp, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ mouseDrag()

void juce::CodeEditorComponent::mouseDrag ( const MouseEvent & event)
overridevirtual

Called when the mouse is moved while a button is held down.

When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval

Reimplemented from juce::MouseListener.

◆ mouseUp()

void juce::CodeEditorComponent::mouseUp ( const MouseEvent & event)
overridevirtual

Called when a mouse button is released.

A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.

The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.

Parameters
Eventdetails about the position and status of the mouse event, including the source component in which it occurred
See also
mouseDown, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

◆ mouseWheelMove()

void juce::CodeEditorComponent::mouseWheelMove ( const MouseEvent & event,
const MouseWheelDetails & wheel )
overridevirtual

Called when the mouse-wheel is moved.

This callback is sent to the component that the mouse is over when the wheel is moved.

If not overridden, a component will forward this message to its parent, so that parent components can collect mouse-wheel messages that happen to child components which aren't interested in them.

Parameters
Eventdetails about the mouse event
wheeldetails about the wheel movement

Reimplemented from juce::MouseListener.

◆ moveCaretDown()

bool juce::CodeEditorComponent::moveCaretDown ( bool selecting)

◆ moveCaretLeft()

bool juce::CodeEditorComponent::moveCaretLeft ( bool moveInWholeWordSteps,
bool selecting )

◆ moveCaretRight()

bool juce::CodeEditorComponent::moveCaretRight ( bool moveInWholeWordSteps,
bool selecting )

◆ moveCaretTo()

void juce::CodeEditorComponent::moveCaretTo ( const CodeDocument::Position & newPos,
bool selecting )

Moves the caret. If selecting is true, the section of the document between the current caret position and the new one will become selected. If false, any currently selected region will be deselected.

◆ moveCaretToEnd()

bool juce::CodeEditorComponent::moveCaretToEnd ( bool selecting)

◆ moveCaretToEndOfLine()

bool juce::CodeEditorComponent::moveCaretToEndOfLine ( bool selecting)

◆ moveCaretToStartOfLine()

bool juce::CodeEditorComponent::moveCaretToStartOfLine ( bool selecting)

◆ moveCaretToTop()

bool juce::CodeEditorComponent::moveCaretToTop ( bool selecting)

◆ moveCaretUp()

bool juce::CodeEditorComponent::moveCaretUp ( bool selecting)

◆ moveLineDelta()

void juce::CodeEditorComponent::moveLineDelta ( int delta,
bool selecting )
private

◆ newTransaction()

void juce::CodeEditorComponent::newTransaction ( )
private

◆ pageDown()

bool juce::CodeEditorComponent::pageDown ( bool selecting)

◆ pageUp()

bool juce::CodeEditorComponent::pageUp ( bool selecting)

◆ paint()

void juce::CodeEditorComponent::paint ( Graphics & g)
overridevirtual

Components can override this method to draw their content.

The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.

Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.

If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In JUCE (and almost all modern UI frameworks), you never redraw something synchronously.

You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().

Parameters
gthe graphics context that must be used to do the drawing operations.
See also
repaint, paintOverChildren, Graphics

Reimplemented from juce::Component.

◆ pasteFromClipboard()

bool juce::CodeEditorComponent::pasteFromClipboard ( )
virtual

◆ perform()

bool juce::CodeEditorComponent::perform ( const InvocationInfo & info)
overridevirtual

This must actually perform the specified command.

If this target is able to perform the command specified by the commandID field of the InvocationInfo structure, then it should do so, and must return true.

If it can't handle this command, it should return false, which tells the caller to pass the command on to the next target in line.

See also
invoke, ApplicationCommandManager::invoke

Implements juce::ApplicationCommandTarget.

◆ performCommand()

bool juce::CodeEditorComponent::performCommand ( CommandID commandID)
private

◆ performPopupMenuAction()

void juce::CodeEditorComponent::performPopupMenuAction ( int menuItemID)
virtual

This is called to perform one of the items that was shown on the popup menu.

If you've overridden addPopupMenuItems(), you should also override this to perform the actions that you've added.

If you've overridden addPopupMenuItems() but have still left the default items on the menu, remember to call the superclass's performPopupMenuAction() so that it can perform the default actions if that's what the user clicked on.

See also
addPopupMenuItems, setPopupMenuEnabled, isPopupMenuEnabled

◆ rebuildLineTokens()

void juce::CodeEditorComponent::rebuildLineTokens ( )
private

◆ rebuildLineTokensAsync()

void juce::CodeEditorComponent::rebuildLineTokensAsync ( )
private

◆ redo()

bool juce::CodeEditorComponent::redo ( )

◆ resized()

void juce::CodeEditorComponent::resized ( )
overridevirtual

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also
moved, setSize

Reimplemented from juce::Component.

◆ retokenise()

void juce::CodeEditorComponent::retokenise ( int startIndex,
int endIndex )

Rebuilds the syntax highlighting for a section of text.

This happens automatically any time the CodeDocument is edited, but this method lets you change text colours even when the CodeDocument hasn't changed.

For example, you could use this to highlight tokens as the cursor moves. To do so you'll need to tell your custom CodeTokeniser where the token you want to highlight is, and make it return a special type of token. Then you should call this method supplying the range of the highlighted text.

See also
CodeTokeniser

◆ scrollBy()

void juce::CodeEditorComponent::scrollBy ( int deltaLines)

◆ scrollDown()

bool juce::CodeEditorComponent::scrollDown ( )

◆ scrollToColumn()

void juce::CodeEditorComponent::scrollToColumn ( int newFirstColumnOnScreen)

◆ scrollToColumnInternal()

void juce::CodeEditorComponent::scrollToColumnInternal ( double column)
private

◆ scrollToKeepCaretOnScreen()

void juce::CodeEditorComponent::scrollToKeepCaretOnScreen ( )

◆ scrollToKeepLinesOnScreen()

void juce::CodeEditorComponent::scrollToKeepLinesOnScreen ( Range< int > linesToShow)

◆ scrollToLine()

void juce::CodeEditorComponent::scrollToLine ( int newFirstLineOnScreen)

◆ scrollToLineInternal()

void juce::CodeEditorComponent::scrollToLineInternal ( int line)
private

◆ scrollUp()

bool juce::CodeEditorComponent::scrollUp ( )

◆ selectAll()

bool juce::CodeEditorComponent::selectAll ( )

◆ selectRegion()

void juce::CodeEditorComponent::selectRegion ( const CodeDocument::Position & start,
const CodeDocument::Position & end )

◆ setColourScheme()

void juce::CodeEditorComponent::setColourScheme ( const ColourScheme & scheme)

Changes the syntax highlighting scheme. The token type values are dependent on the tokeniser being used - use CodeTokeniser::getTokenTypes() to get a list of the token types.

See also
getColourForTokenType

◆ setCommandManager()

void juce::CodeEditorComponent::setCommandManager ( ApplicationCommandManager * newManager)
noexcept

Specifies a command-manager which the editor will notify whenever the state of any of its commands changes. If you're making use of the editor's ApplicationCommandTarget interface, then you should also use this to tell it which command manager it should use. Make sure that the manager does not go out of scope while the editor is using it. You can pass a nullptr here to disable this.

◆ setFont()

void juce::CodeEditorComponent::setFont ( const Font & newFont)

Changes the font. Make sure you only use a fixed-width font, or this component will look pretty nasty!

◆ setHighlightedRegion()

void juce::CodeEditorComponent::setHighlightedRegion ( const Range< int > & newRange)
overridevirtual

Sets the currently-selected text region.

Implements juce::TextInputTarget.

◆ setLineNumbersShown()

void juce::CodeEditorComponent::setLineNumbersShown ( bool shouldBeShown)

Enables or disables the line-number display in the gutter.

◆ setReadOnly()

void juce::CodeEditorComponent::setReadOnly ( bool shouldBeReadOnly)
noexcept

Makes the editor read-only.

◆ setScrollbarThickness()

void juce::CodeEditorComponent::setScrollbarThickness ( int thickness)

Changes the size of the scrollbars.

◆ setSelection()

void juce::CodeEditorComponent::setSelection ( CodeDocument::Position newSelectionStart,
CodeDocument::Position newSelectionEnd )
private

◆ setTabSize()

void juce::CodeEditorComponent::setTabSize ( int numSpacesPerTab,
bool insertSpacesInsteadOfTabCharacters )

Changes the current tab settings. This lets you change the tab size and whether pressing the tab key inserts a tab character, or its equivalent number of spaces.

◆ setTemporaryUnderlining()

void juce::CodeEditorComponent::setTemporaryUnderlining ( const Array< Range< int > > & underlinedRegions)
overridevirtual

Sets a number of temporarily underlined sections. This is needed by MS Windows input method UI.

Implements juce::TextInputTarget.

◆ skipBackwardsToPreviousTab()

bool juce::CodeEditorComponent::skipBackwardsToPreviousTab ( )
private

◆ undo()

bool juce::CodeEditorComponent::undo ( )

◆ unindentSelection()

void juce::CodeEditorComponent::unindentSelection ( )

◆ updateCachedIterators()

void juce::CodeEditorComponent::updateCachedIterators ( int maxLineNum)
private

◆ updateCaretPosition()

void juce::CodeEditorComponent::updateCaretPosition ( )
privatevirtual

◆ updateScrollBars()

void juce::CodeEditorComponent::updateScrollBars ( )
private

Member Data Documentation

◆ appCommandManager

ApplicationCommandManager* juce::CodeEditorComponent::appCommandManager = nullptr
private

◆ cachedIterators

Array<CodeDocument::Iterator> juce::CodeEditorComponent::cachedIterators
private

◆ caret

std::unique_ptr<CaretComponent> juce::CodeEditorComponent::caret
private

◆ caretPos

CodeDocument::Position juce::CodeEditorComponent::caretPos
private

◆ charWidth

float juce::CodeEditorComponent::charWidth = 0
private

◆ codeTokeniser

CodeTokeniser* juce::CodeEditorComponent::codeTokeniser
private

◆ colourScheme

ColourScheme juce::CodeEditorComponent::colourScheme
private

◆ columnsOnScreen

int juce::CodeEditorComponent::columnsOnScreen = 0
private

◆ columnToTryToMaintain

int juce::CodeEditorComponent::columnToTryToMaintain = -1
private

◆ document

CodeDocument& juce::CodeEditorComponent::document
private

◆ dragType

DragType juce::CodeEditorComponent::dragType = notDragging
private

◆ firstLineOnScreen

int juce::CodeEditorComponent::firstLineOnScreen = 0
private

◆ font

Font juce::CodeEditorComponent::font
private

◆ gutter

std::unique_ptr<GutterComponent> juce::CodeEditorComponent::gutter
private

◆ horizontalScrollBar

ScrollBar juce::CodeEditorComponent::horizontalScrollBar { false }
private

◆ lineHeight

int juce::CodeEditorComponent::lineHeight = 0
private

◆ lines

OwnedArray<CodeEditorLine> juce::CodeEditorComponent::lines
private

◆ linesOnScreen

int juce::CodeEditorComponent::linesOnScreen = 0
private

◆ pimpl

std::unique_ptr<Pimpl> juce::CodeEditorComponent::pimpl
private

◆ readOnly

bool juce::CodeEditorComponent::readOnly = false
private

◆ scrollbarThickness

int juce::CodeEditorComponent::scrollbarThickness = 16
private

◆ selectionEnd

CodeDocument::Position juce::CodeEditorComponent::selectionEnd
private

◆ selectionStart

CodeDocument::Position juce::CodeEditorComponent::selectionStart
private

◆ shouldFollowDocumentChanges

bool juce::CodeEditorComponent::shouldFollowDocumentChanges = false
private

◆ showLineNumbers

bool juce::CodeEditorComponent::showLineNumbers = false
private

◆ spacesPerTab

int juce::CodeEditorComponent::spacesPerTab = 4
private

◆ useSpacesForTabs

bool juce::CodeEditorComponent::useSpacesForTabs = true
private

◆ verticalScrollBar

ScrollBar juce::CodeEditorComponent::verticalScrollBar { true }
private

◆ xOffset

double juce::CodeEditorComponent::xOffset = 0
private

The documentation for this class was generated from the following files: