Skip to content

Commit

Permalink
Merge pull request #1 in VSTSDK/vstgui from develop to master
Browse files Browse the repository at this point in the history
* commit 'ca0bf2d843b3bed8163cdde26db21bad18270f71':
  add ITextEditListener
  • Loading branch information
scheffle committed Aug 20, 2020
2 parents e530620 + ca0bf2d commit 83c6dc9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions vstgui/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ set(${target}_common_sources
controls/icommandmenuitemtarget.h
controls/icontrollistener.h
controls/ioptionmenulistener.h
controls/itexteditlistener.h
controls/itextlabellistener.h
copenglview.cpp
copenglview.h
Expand Down
20 changes: 18 additions & 2 deletions vstgui/lib/controls/ctextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE

#include "ctextedit.h"
#include "itexteditlistener.h"
#include "../cframe.h"
#include "../platform/iplatformframe.h"
#include <cassert>
Expand Down Expand Up @@ -95,6 +96,18 @@ bool CTextEdit::getSecureStyle () const
return secureStyle;
}

//------------------------------------------------------------------------
void CTextEdit::registerTextEditListener (ITextEditListener* listener)
{
textEditListeners.add (listener);
}

//------------------------------------------------------------------------
void CTextEdit::unregisterTextEditListener (ITextEditListener* listener)
{
textEditListeners.remove (listener);
}

//------------------------------------------------------------------------
void CTextEdit::setValue (float val)
{
Expand Down Expand Up @@ -336,6 +349,8 @@ void CTextEdit::createPlatformTextEdit ()

bWasReturnPressed = false;
platformControl = getFrame ()->getPlatformFrame ()->createPlatformTextEdit (this);
textEditListeners.forEach (
[this] (ITextEditListener* l) { l->onTextEditPlatformControlTookFocus (this); });
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -368,11 +383,13 @@ void CTextEdit::looseFocus ()

auto _platformControl = platformControl;
platformControl = nullptr;

updateText (_platformControl);

_platformControl = nullptr;

textEditListeners.forEach (
[this] (ITextEditListener* l) { l->onTextEditPlatformControlLostFocus (this); });

// if you want to destroy the text edit do it with the loose focus message
CView* receiver = getParentView () ? getParentView () : getFrame ();
while (receiver)
Expand Down Expand Up @@ -402,4 +419,3 @@ void CTextEdit::updateText (IPlatformTextEdit* pte)
}

} // VSTGUI

5 changes: 5 additions & 0 deletions vstgui/lib/controls/ctextedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "ctextlabel.h"
#include "../dispatchlist.h"
#include "../platform/iplatformtextedit.h"
#include <functional>

Expand Down Expand Up @@ -60,6 +61,9 @@ class CTextEdit : public CTextLabel, public IPlatformTextEditCallback

virtual void setPlaceholderString (const UTF8String& str);
const UTF8String& getPlaceholderString () const { return placeholderString; }

void registerTextEditListener (ITextEditListener* listener);
void unregisterTextEditListener (ITextEditListener* listener);
//@}

// overrides
Expand Down Expand Up @@ -112,6 +116,7 @@ class CTextEdit : public CTextLabel, public IPlatformTextEditCallback
bool secureStyle {false};
mutable SharedPointer<CFontDesc> platformFont;
UTF8String placeholderString;
DispatchList<ITextEditListener*> textEditListeners;
};

} // VSTGUI
33 changes: 33 additions & 0 deletions vstgui/lib/controls/itexteditlistener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of VSTGUI. It is subject to the license terms
// in the LICENSE file found in the top-level directory of this
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE

#pragma once

#include "../vstguifwd.h"

namespace VSTGUI {

//------------------------------------------------------------------------
/** Listener for a text edit
* @ingroup new_in_4_10
*/
class ITextEditListener
{
public:
/** called when the native platform text edit control was created and started to listen for keyboard input. */
virtual void onTextEditPlatformControlTookFocus (CTextEdit* textEdit) = 0;
/** called when the natvie platform text edit control is going to be destroyed. */
virtual void onTextEditPlatformControlLostFocus (CTextEdit* textEdit) = 0;
};

//------------------------------------------------------------------------
class TextEditListenerAdapter : public ITextEditListener
{
public:
void onTextEditPlatformControlTookFocus (CTextEdit* textEdit) override {}
void onTextEditPlatformControlLostFocus (CTextEdit* textEdit) override {}
};

//------------------------------------------------------------------------
} // VSTGUI
1 change: 1 addition & 0 deletions vstgui/lib/vstguifwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class IDraggingSession;
class IDropTarget;
class ICommandMenuItemTarget;
class IOptionMenuListener;
class ITextEditListener;
class ITextLabelListener;
class IListControlDrawer;
class IListControlConfigurator;
Expand Down

0 comments on commit 83c6dc9

Please sign in to comment.