Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Host

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Public handle for a tooltip registration created through MASApplicationWindow services.
    ''' Disposing the handle unregisters the target from the real root-owned MASTooltips service.
    ''' </summary>
    Public NotInheritable Class MASApplicationTooltipTarget
        Implements IDisposable

        Private ReadOnly _target As MASTooltipTarget
        Private _disposed As Boolean

        Friend Sub New(target As MASTooltipTarget)
            _target = target
        End Sub

        Public ReadOnly Property IsRegistered As Boolean
            Get
                Return Not _disposed AndAlso _target IsNot Nothing
            End Get
        End Property

        Public Sub Remove()
            Dispose()
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            If _disposed Then Return
            _disposed = True

            Try
                If _target IsNot Nothing Then
                    _target.Remove()
                End If
            Catch masCaughtException1 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowBoundary(masCaughtException1, "MASApplicationTooltipTarget.Dispose.Remove")
            End Try
        End Sub

    End Class

End Namespace
