Skip to content

Commit

Permalink
[NUI] Block native callback if InputMethodContext is disposed
Browse files Browse the repository at this point in the history
Block native callback if InputMethodContext is disposed
  • Loading branch information
Jaehyun-Cho authored and dongsug-song committed Dec 2, 2024
1 parent 69fb40e commit e37dc51
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/Tizen.NUI/src/public/Input/InputMethodContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,41 @@ protected override void Dispose(DisposeTypes type)
//You should not access any managed member here except static instance
//because the execution order of Finalizes is non-deterministic.

if (activatedEventCallback != null)
{
ActivatedSignal().Disconnect(activatedEventCallback);
}

if (eventReceivedEventCallback != null)
{
EventReceivedSignal().Disconnect(eventReceivedEventCallback);
}

if (statusChangedEventCallback != null)
{
StatusChangedSignal().Disconnect(statusChangedEventCallback);
}

if (resizedEventCallback != null)
{
ResizedSignal().Disconnect(resizedEventCallback);
}

if (languageChangedEventCallback != null)
{
LanguageChangedSignal().Disconnect(languageChangedEventCallback);
}

if (keyboardTypeChangedEventCallback != null)
{
KeyboardTypeChangedSignal().Disconnect(keyboardTypeChangedEventCallback);
}

if (contentReceivedEventCallback != null)
{
ContentReceivedSignal().Disconnect(contentReceivedEventCallback);
}

base.Dispose(type);
}

Expand All @@ -832,6 +862,12 @@ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef

private void OnActivated(IntPtr data)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

ActivatedEventArgs e = new ActivatedEventArgs();

if (data != null)
Expand All @@ -847,6 +883,12 @@ private void OnActivated(IntPtr data)

private IntPtr OnEventReceived(IntPtr inputMethodContext, IntPtr eventData)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return IntPtr.Zero;
}

CallbackData callbackData = null;

EventReceivedEventArgs e = new EventReceivedEventArgs();
Expand Down Expand Up @@ -876,6 +918,12 @@ private IntPtr OnEventReceived(IntPtr inputMethodContext, IntPtr eventData)

private void OnStatusChanged(bool statusChanged)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

StatusChangedEventArgs e = new StatusChangedEventArgs();

e.StatusChanged = statusChanged;
Expand All @@ -888,6 +936,12 @@ private void OnStatusChanged(bool statusChanged)

private void OnResized(int resized)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

ResizedEventArgs e = new ResizedEventArgs();
e.Resized = resized;

Expand All @@ -899,6 +953,12 @@ private void OnResized(int resized)

private void OnLanguageChanged(int languageChanged)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

LanguageChangedEventArgs e = new LanguageChangedEventArgs();
e.LanguageChanged = languageChanged;

Expand All @@ -910,6 +970,12 @@ private void OnLanguageChanged(int languageChanged)

private void OnKeyboardTypeChanged(KeyboardType type)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

KeyboardTypeChangedEventArgs e = new KeyboardTypeChangedEventArgs();

e.KeyboardType = type;
Expand All @@ -922,6 +988,12 @@ private void OnKeyboardTypeChanged(KeyboardType type)

private void OnContentReceived(string content, string description, string mimeType)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if InputMethodContext is disposed or queued for disposal.
return;
}

ContentReceivedEventArgs e = new ContentReceivedEventArgs();
e.Content = content;
e.Description = description;
Expand Down

0 comments on commit e37dc51

Please sign in to comment.