Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / keyboard / juce_CaretComponent.cpp
blobc73eb4e35bfdfeff90401499811907d245c54378
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_CaretComponent.h"
33 //==============================================================================
34 CaretComponent::CaretComponent (Component* const keyFocusOwner)
35 : owner (keyFocusOwner)
37 setAlwaysOnTop (true);
38 setInterceptsMouseClicks (false, false);
41 CaretComponent::~CaretComponent()
45 void CaretComponent::paint (Graphics& g)
47 g.fillAll (findColour (caretColourId, true));
50 void CaretComponent::timerCallback()
52 setVisible (shouldBeShown() && ! isVisible());
55 void CaretComponent::setCaretPosition (const Rectangle<int>& characterArea)
57 startTimer (380);
58 setVisible (shouldBeShown());
59 setBounds (characterArea.withWidth (2));
62 bool CaretComponent::shouldBeShown() const
64 return owner == nullptr || (owner->hasKeyboardFocus (true)
65 && ! owner->isCurrentlyBlockedByAnotherModalComponent());
69 END_JUCE_NAMESPACE