1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-04 03:40:07 +00:00

Minor additions to Rectangle and CodeEditorComponent. Jucer development.

This commit is contained in:
Julian Storer 2010-04-28 14:51:11 +01:00
parent 5093ecbc84
commit 49b47cc866
13 changed files with 479 additions and 99 deletions

View file

@ -431,6 +431,7 @@ void CodeDocument::Position::setPositionMaintained (const bool isMaintained) thr
}
else
{
// If this happens, you may have deleted the document while there are Position objects that are still using it...
jassert (owner->positionsToMaintain.contains (this));
owner->positionsToMaintain.removeValue (this);
}

View file

@ -37,7 +37,8 @@ class CodeEditorComponent::CaretComponent : public Component,
public Timer
{
public:
CaretComponent()
CaretComponent (CodeEditorComponent& owner_)
: owner (owner_)
{
setAlwaysOnTop (true);
setInterceptsMouseClicks (false, false);
@ -49,27 +50,29 @@ public:
void paint (Graphics& g)
{
if (getParentComponent()->hasKeyboardFocus (true))
g.fillAll (findColour (CodeEditorComponent::caretColourId));
g.fillAll (findColour (CodeEditorComponent::caretColourId));
}
void timerCallback()
{
setVisible (! isVisible());
setVisible (shouldBeShown() && ! isVisible());
}
void updatePosition (CodeEditorComponent& owner)
void updatePosition()
{
startTimer (400);
setVisible (true);
setVisible (shouldBeShown());
const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
setBounds (owner.getCharacterBounds (owner.getCaretPos()).withWidth (2));
}
private:
CodeEditorComponent& owner;
CaretComponent (const CaretComponent&);
CaretComponent& operator= (const CaretComponent&);
bool shouldBeShown() const { return owner.hasKeyboardFocus (true); }
};
//==============================================================================
@ -314,7 +317,7 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
horizontalScrollBar->setSingleStepSize (1.0);
addAndMakeVisible (caret = new CaretComponent());
addAndMakeVisible (caret = new CaretComponent (*this));
Font f (12.0f);
f.setTypefaceName (Font::getDefaultMonospacedFontName());
@ -353,7 +356,7 @@ void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& aff
triggerAsyncUpdate();
caret->updatePosition (*this);
caret->updatePosition();
columnToTryToMaintain = -1;
if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
@ -373,7 +376,7 @@ void CodeEditorComponent::resized()
columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
lines.clear();
rebuildLineTokens();
caret->updatePosition (*this);
caret->updatePosition();
verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
@ -516,7 +519,7 @@ void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, con
deselectAll();
}
caret->updatePosition (*this);
caret->updatePosition();
scrollToKeepCaretOnScreen();
updateScrollBars();
}
@ -547,7 +550,7 @@ void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
if (newFirstLineOnScreen != firstLineOnScreen)
{
firstLineOnScreen = newFirstLineOnScreen;
caret->updatePosition (*this);
caret->updatePosition();
updateCachedIterators (firstLineOnScreen);
triggerAsyncUpdate();
@ -561,7 +564,7 @@ void CodeEditorComponent::scrollToColumnInternal (double column)
if (xOffset != newOffset)
{
xOffset = newOffset;
caret->updatePosition (*this);
caret->updatePosition();
repaint();
}
}
@ -1071,8 +1074,16 @@ void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
{
verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
if ((verticalScrollBar->isVisible() && wheelIncrementY != 0)
|| (horizontalScrollBar->isVisible() && wheelIncrementX != 0))
{
verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
}
else
{
Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
}
}
void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
@ -1083,6 +1094,17 @@ void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, doub
scrollToColumnInternal (newRangeStart);
}
//==============================================================================
void CodeEditorComponent::focusGained (FocusChangeType cause)
{
caret->updatePosition();
}
void CodeEditorComponent::focusLost (FocusChangeType cause)
{
caret->updatePosition();
}
//==============================================================================
void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
{

View file

@ -175,6 +175,9 @@ public:
*/
void setFont (const Font& newFont);
/** Returns the font that the editor is using. */
const Font& getFont() const throw() { return font; }
/** Resets the syntax highlighting colours to the default ones provided by the
code tokeniser.
@see CodeTokeniser::getDefaultColour
@ -217,6 +220,9 @@ public:
/** Changes the size of the scrollbars. */
void setScrollbarThickness (int thickness) throw();
/** Returns the thickness of the scrollbars. */
int getScrollbarThickness() const throw() { return scrollbarThickness; }
//==============================================================================
/** @internal */
void resized();
@ -235,6 +241,10 @@ public:
/** @internal */
void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
/** @internal */
void focusGained (FocusChangeType cause);
/** @internal */
void focusLost (FocusChangeType cause);
/** @internal */
void timerCallback();
/** @internal */
void scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart);