Imports System.Collections.ObjectModel
Imports System.ComponentModel

Partial Class OmagCUTDictionary
   Inherits ResourceDictionary

   Dim m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)

   ' Evento della TextBox con Style che permette di aprire in automatico la calcolatrice
   'Friend Sub NumericKeyboard_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs)
   '   ' Recupero dati da sorgente
   '   Dim sTitle As String = String.Empty
   '   Dim sText As String = String.Empty
   '   Dim TxBx As TextBox = CType(e.Source, TextBox)
   '   If Not IsNothing(TxBx) Then
   '      sText = TxBx.Text
   '      Dim AssocLabel As Label = TxBx.Tag
   '      If Not IsNothing(AssocLabel) Then
   '         sTitle = AssocLabel.Content
   '      End If
   '   End If
   '   ' Creo calcolatrice
   '   Dim NumericKeyboardWD As New NumericKeyboardWD(sTitle, sText, e.Source)
   '   ' La visualizzo
   '   NumericKeyboardWD.ShowDialog()
   'End Sub

   ' Evento della TextBox con Style che permette di aggiornare in automatico il componente con il nuovo valore
   'Private Sub NumericKeyboard_TextChanged(sender As Object, e As TextChangedEventArgs)
   '   Select Case m_MainWindow.m_ActivePage
   '      Case MainWindow.Pages.Draw
   '         If Not m_MainWindow.m_DrawPageUC.m_bShowVar Then
   '            m_MainWindow.m_DrawPageUC.UpdateView()
   '         End If
   '      Case MainWindow.Pages.RawPart
   '         If Not m_MainWindow.m_RawPartPage.m_bShowVar Then
   '            m_MainWindow.m_RawPartPage.UpdateRawPart()
   '         End If
   '   End Select
   'End Sub

End Class

Namespace TreeViewItem

   Public Class CathegoryItem
      Inherits TreeViewItemBase

      'Private m_sTitle As String
      Private m_sPictureString As String
      Private m_nTType As Integer
      Private m_Items As ObservableCollection(Of CustomItem)
      Friend m_IsValidTool As Boolean

      Public ReadOnly Property PictureString As String
         Get
            Return "/Resources/ToolsTreeViewImages/Folder.png"
         End Get
      End Property

      Public ReadOnly Property nTType As Integer
         Get
            Return m_nTType
         End Get
      End Property

      Public Property Items As ObservableCollection(Of CustomItem)
         Get
            Return m_Items
         End Get
         Set(value As ObservableCollection(Of CustomItem))
            m_Items = value
         End Set
      End Property

      Sub New(sName As String, nType As Integer)
         Name = sName
         m_nTType = nType
         Me.Items = New ObservableCollection(Of CustomItem)
      End Sub

   End Class

   Public Class CustomItem
      Inherits TreeViewItemBase

      'Private m_sTitle As String
      Private m_nType As Integer

      'Private m_sName As String
      'Public Property Name As String
      '   Get
      '      Return m_sName
      '   End Get
      '   Set(value As String)
      '      m_sName = value
      '   End Set
      'End Property

      Public ReadOnly Property nType As Integer
         Get
            Return m_nType
         End Get
      End Property

      Friend m_IsValidTool As Boolean = True

      Public Property IsValidTool As Boolean
         Get
            Return m_IsValidTool
         End Get
         Set(value As Boolean)
            If value <> m_IsValidTool Then
               m_IsValidTool = value
               NotifyPropertyChanged("ToolColor")
            End If
         End Set
      End Property

      Sub New(Title As String, nType As Integer)
         Me.Name = Title
         m_nType = nType
      End Sub

      Sub New(sName As String, nType As Integer, bIsValidTool As Boolean)
         MyBase.Name = sName
         m_nType = nType
         m_IsValidTool = bIsValidTool
      End Sub

   End Class

   Public Class PartCathegoryItem
      Inherits TreeViewItemBase

      Private m_nFType As Integer
      Private m_Items As ObservableCollection(Of PartCustomItem)

      Public ReadOnly Property PictureString As String
         Get
            Return "/Resources/ToolsTreeViewImages/Folder.png"
         End Get
      End Property

      Public ReadOnly Property nFType As Integer
         Get
            Return m_nFType
         End Get
      End Property

      Public Property Items As ObservableCollection(Of PartCustomItem)
         Get
            Return m_Items
         End Get
         Set(value As ObservableCollection(Of PartCustomItem))
            m_Items = value
         End Set
      End Property

      Sub New(sName As String, nType As Integer)
         Name = sName
         m_nFType = nType
         Me.Items = New ObservableCollection(Of PartCustomItem)
      End Sub

   End Class

   Public Class PartCustomItem
      Inherits TreeViewItemBase

      Private m_nType As Integer
      Private m_bIsActive As Boolean
      Private m_sText1 As String
      Private m_sText2 As String

      Public Property sText1 As String
         Get
            Return m_sText1
         End Get
         Set(value As String)
            m_sText1 = value
            NotifyPropertyChanged("sText1")
         End Set
      End Property

      Public Property sText2 As String
         Get
            Return m_sText2
         End Get
         Set(value As String)
            m_sText2 = value
            NotifyPropertyChanged("sText2")
         End Set
      End Property

      Public ReadOnly Property nType As Integer
         Get
            Return m_nType
         End Get
      End Property

      Public Property bIsActive As Boolean
         Get
            Return m_bIsActive
         End Get
         Set(value As Boolean)
         If value <> m_bIsActive Then
            m_bIsActive = value
            NotifyPropertyChanged("bIsActive")
         End If
         End Set
      End Property

      Sub New(Title As String, nType As Integer, sText1 As String, sText2 As String)
         Me.Name = Title
         m_nType = nType
         m_sText1 = sText1
         m_sText2 = sText2
         m_bIsActive = True
      End Sub

      Sub New(Title As String, nType As Integer, sText1 As String, sText2 As String, bIsActive As Boolean)
         Me.Name = Title
         m_nType = nType
         m_sText1 = sText1
         m_sText2 = sText2
         m_bIsActive = bIsActive
      End Sub

   End Class

   Public Class TreeViewItemBase
      Implements INotifyPropertyChanged

      Private m_Name As String
      Public Property Name As String
         Get
            Return m_Name
         End Get
         Set(value As String)
            If (value <> m_Name) Then
               m_Name = value
               NotifyPropertyChanged("Name")
            End If
         End Set
      End Property

      Private m_isSelected As Boolean
      Public Property IsSelected As Boolean
         Get
            Return m_isSelected
         End Get
         Set(value As Boolean)
            If (value <> m_isSelected) Then
               m_isSelected = value
               NotifyPropertyChanged("IsSelected")
            End If
         End Set
      End Property

      Private m_isExpanded As Boolean
      Public Property IsExpanded As Boolean
         Get
            Return m_isExpanded
         End Get
         Set(value As Boolean)
            If (value <> m_isExpanded) Then
               m_isExpanded = value
               NotifyPropertyChanged("IsExpanded")
            End If
         End Set
      End Property

      Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged


      Public Sub NotifyPropertyChanged(propName As String)
         RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
      End Sub

   End Class

End Namespace


Namespace ArithmeticConverterNameSpace

   Public Class CheckboxConverter
      Implements IMultiValueConverter

      Public Function Convert(values() As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IMultiValueConverter.Convert
         If values.Length <> 2 Then
            Throw New ArgumentException("There should be three values.")
         End If

         If String.IsNullOrEmpty(values(0).ToString) Then
            values(0) = "0"
         End If

         If String.IsNullOrEmpty(values(1).ToString()) Then
            values(2) = "0"
         End If

         Dim x As Double
         If Not Double.TryParse(values(0).ToString(), x) Then
            Throw New ArgumentException("values[0] must parse to double")
         End If

         Dim y As Double
         If Not Double.TryParse(values(1).ToString(), y) Then
            Throw New ArgumentException("values[0] must parse to double")
         End If

         Return (x / y) - 1

      End Function

      Public Function ConvertBack(value As Object, targetTypes() As Type, parameter As Object, culture As Globalization.CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
         Throw New NotImplementedException()
      End Function
   End Class

End Namespace
