'-----------------------------------------------------------------------------------------------------------
' MainWindow_DpiChanged.vb File
'
' Description:
'     Handles custom image updating when the application resolution changed.
'
' copyright:		© Text Control GmbH
'-----------------------------------------------------------------------------------------------------------
Imports TXTextControl.Windows.Forms
Imports TXTextControl.Windows.Forms.Ribbon

Namespace TXTextControl.Words
    Partial Class MainWindow

        '-----------------------------------------------------------------------------------------------------------
        ' M E M B E R   V A R I A B L E S
        '-----------------------------------------------------------------------------------------------------------

        Private ReadOnly m_lstCustomRibbonButtons As List(Of RibbonButton) = New List(Of RibbonButton)()
        Private m_fDPI As Single = 0


        '-----------------------------------------------------------------------------------------------------------
        ' O V E R R I D D E N   M E T H O D S
        '-----------------------------------------------------------------------------------------------------------

        '-----------------------------------------------------------------------------------------------------------
        ' WndProc Method (overridden)
        ' Overridden to get the DPI value when the window is created and to update the icons of the custom 
        ' ribbon buttons and groups when the dpi value changed.
        '
        ' Parameters:
        '      WndProc:   The Windows Message to process.
        '-----------------------------------------------------------------------------------------------------------
        Protected Overrides Sub WndProc(ByRef m As Message)
            Select Case m.Msg
                Case &H1 ' WM_CREATE
                    ' Get the DPI value from the created handle.
                    Using g = Graphics.FromHwnd(Handle)
                        m_fDPI = g.DpiX
                    End Using
                Case &H2E0 ' WM_DPICHANGED
                    ' Get the new DPI value when the dpi value changed.
                    Dim iNewDPI = CInt(m.WParam) And &HFFFF
                    If m_fDPI <> CSharpImpl.Assign(m_fDPI, iNewDPI) Then
                        ' Step through those custom ribbon buttons that show an image that is provided
                        ' by the TXTextControl.ResourceProvider
                        For Each customButton In m_lstCustomRibbonButtons
                            customButton.SmallIcon = ResourceProvider.GetSmallIcon(customButton.Name, m_fDPI)
                            customButton.LargeIcon = ResourceProvider.GetLargeIcon(customButton.Name, m_fDPI)
                        Next

                        ' Update the icons of those ribbons and groups that use a custom SVG.  

                        ' Update the small icons
                        m_rmbtnOpenSampleTemplate.SmallIcon = GetSmallIcon("OpenSampleTemplate_Small.svg")

                        m_rbtnSampleDatabaseButton.SmallIcon = GetSmallIcon("SampleDatabase_Small.svg")

                        m_rgMerge.SmallIcon = CSharpImpl.Assign(m_rbtnMergeAndExport.SmallIcon, GetSmallIcon("MergeAndExport_Small.svg"))

                        m_rgMergeResultsTab_ResultGroup.SmallIcon = ResourceProvider.GetSmallIcon(m_rgMergeResultsTab_ResultGroup.Name, m_fDPI)
                        m_rgNavigateGroup.SmallIcon = ResourceProvider.GetSmallIcon(m_rgMergeResultsTab_ResultGroup.Name, m_fDPI)


                        ' Update the large icons.
                        m_rmbtnOpenSampleTemplate.LargeIcon = GetLargeIcon("OpenSampleTemplate_Large.svg")

                        m_rgMerge.LargeIcon = CSharpImpl.Assign(m_rbtnMergeAndExport.LargeIcon, GetSmallIcon("MergeAndExport_Large.svg"))

                        m_rgMergeResultsTab_ResultGroup.LargeIcon = ResourceProvider.GetLargeIcon(m_rgMergeResultsTab_ResultGroup.Name, m_fDPI)
                        m_rgNavigateGroup.LargeIcon = ResourceProvider.GetLargeIcon(m_rgNavigateGroup.Name, m_fDPI)
                    End If
            End Select
            MyBase.WndProc(m)
        End Sub
    End Class
End Namespace
