Mini Kabibi Habibi

Current Path : C:/Program Files (x86)/DevExpress/DXperience 13.1/Sources/FrameTemplates/VB/
Upload File :
Current File : C:/Program Files (x86)/DevExpress/DXperience 13.1/Sources/FrameTemplates/VB/PopupForm.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Model
Imports DevExpress.ExpressApp.Templates
Imports DevExpress.ExpressApp.Utils
Imports DevExpress.ExpressApp.Win
Imports DevExpress.ExpressApp.Win.Controls
Imports DevExpress.ExpressApp.Win.SystemModule
Imports DevExpress.ExpressApp.Win.Templates.ActionContainers
Imports DevExpress.ExpressApp.Win.Utils
Imports DevExpress.Utils.Controls
Imports DevExpress.XtraLayout

Imports DevExpress.ExpressApp.Win.Templates
Partial Public Class PopupForm
    Inherits DevExpress.XtraEditors.XtraForm
    Implements IWindowTemplate, ISupportViewChanged, ISupportStoreSettings, IViewSiteTemplate, IBarManagerHolder
    Private Const viewControlPreferredWidth As Integer = 350
    Private Const viewControlPreferredHeight As Integer = 215
    Private Const minWidth As Integer = 420
    Private Const minHeight As Integer = 150
    Private Const FrameTemplatesPopupForm As String = "FrameTemplates\PopupForm"
    Private autoShrink_Renamed As Boolean
    Private ignoreMinimumSize As Boolean
    Private view As DevExpress.ExpressApp.View
    Private locaizationHelper As TemplatesHelper
    Private Sub OnSettingsReloaded()
        If SettingsReloadedEvent IsNot Nothing Then
            RaiseEvent SettingsReloaded(Me, EventArgs.Empty)
        End If
    End Sub
    Private Sub MoveFocusToFirstViewControl()
        If viewSitePanel IsNot Nothing Then
            viewSitePanel.SelectNextControl(viewSitePanel, True, True, True, False)
        End If
    End Sub
    Private Function GetViewSitePanelMinSize() As Size
        Dim viewControl As Control = viewSitePanel.Controls(0)
        If TypeOf viewControl Is LayoutControl Then
            Dim layoutControl As LayoutControl = TryCast(viewControl, LayoutControl)
            layoutControl.BeginUpdate()
            layoutControl.EndUpdate()
        End If
        Dim resizableControl As IXtraResizableControl = TryCast(viewControl, IXtraResizableControl)
        If resizableControl IsNot Nothing Then
            Return resizableControl.MinSize
        End If
        Return viewControl.MinimumSize
    End Function
    Public Sub UpdateSize()
        If viewSitePanel.Controls.Count > 0 Then
            Dim viewControlMinimumSize As Size = GetViewSitePanelMinSize()

            Dim nonClientWidth As Integer = Size.Width - ClientSize.Width
            Dim nonClientHeight As Integer = Size.Height - ClientSize.Height

            Dim viewControlMinWidthWithPaddings As Integer = viewSitePanel.Padding.Left + viewSitePanel.Padding.Right + viewControlMinimumSize.Width
            Dim viewControlMinHeightWithPaddings As Integer = viewSitePanel.Padding.Top + viewSitePanel.Padding.Bottom + viewControlMinimumSize.Height

            Dim calculatedClientSize As Size
            If WindowState = FormWindowState.Maximized Then
                calculatedClientSize = New Size(Math.Max(ClientSize.Width + viewControlMinWidthWithPaddings - viewSitePanel.Width, ClientSize.Width), Math.Max(ClientSize.Height + viewControlMinHeightWithPaddings - viewSitePanel.Height, ClientSize.Height))
            Else
                calculatedClientSize = New Size(ClientSize.Width + viewControlMinWidthWithPaddings - viewSitePanel.Width, ClientSize.Height + viewControlMinHeightWithPaddings - viewSitePanel.Height)
            End If
            If CustomizeClientSizeEvent IsNot Nothing Then
                Dim eventArgs As New CustomSizeEventArgs(calculatedClientSize)
                RaiseEvent CustomizeClientSize(Me, eventArgs)
                If eventArgs.Handled Then
                    calculatedClientSize = eventArgs.CustomSize
                End If
            End If
            ClientSize = calculatedClientSize

            If (Not ignoreMinimumSize) Then
                Dim calculatedMinumumSize As New Size(Math.Max(nonClientWidth + ClientSize.Width + viewControlMinWidthWithPaddings - viewSitePanel.Width, minWidth), Math.Max(nonClientHeight + ClientSize.Height + viewControlMinHeightWithPaddings - viewSitePanel.Height, minHeight))
                If CustomizeMinimumSizeEvent IsNot Nothing Then
                    Dim eventArgs As New CustomSizeEventArgs(calculatedMinumumSize)
                    RaiseEvent CustomizeMinimumSize(Me, eventArgs)
                    If eventArgs.Handled Then
                        calculatedMinumumSize = eventArgs.CustomSize
                    End If
                End If
                MinimumSize = calculatedMinumumSize
            End If

        End If
    End Sub
    Protected Overridable Sub ReloadSettingsCore()
        If modelTemplate IsNot Nothing AndAlso IsSizeable Then
            formStateModelSynchronizer.ApplyModel()
        End If
    End Sub
    Protected Overridable Sub OnBarMangerChanged()
        RaiseEvent BarManagerChanged(Me, EventArgs.Empty)
    End Sub
    Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
        MyBase.OnHandleCreated(e)
        If autoShrink_Renamed Then
            UpdateSize()
        End If
    End Sub
    Protected Overrides Sub OnVisibleChanged(ByVal e As EventArgs)
        MyBase.OnVisibleChanged(e)
        If Visible AndAlso autoShrink_Renamed Then
            UpdateSize()
        End If
    End Sub
    Protected Overrides Sub OnShown(ByVal e As EventArgs)
        MyBase.OnShown(e)
        MoveFocusToFirstViewControl()
    End Sub
    Public Sub New()
        InitializeComponent()
        NativeMethods.SetExecutingApplicationIcon(Me)
        autoShrink_Renamed = True
        ignoreMinimumSize = False
        ShowInTaskbar = True
        KeyPreview = True

        ClientSize = New Size(ClientSize.Width - viewSitePanel.Width + viewSitePanel.Padding.Left + viewSitePanel.Padding.Right + viewControlPreferredWidth, ClientSize.Height - viewSitePanel.Height + viewSitePanel.Padding.Top + viewSitePanel.Padding.Bottom + viewControlPreferredHeight)
    End Sub
    Public Sub AddControl(ByVal control As Control, ByVal caption As String)
        If control IsNot Nothing Then
            viewSitePanel.Controls.Add(control)
            control.Dock = DockStyle.Fill
            Text = caption
        End If
    End Sub
    Public Overridable Function GetContainers() As ICollection(Of IActionContainer) Implements IFrameTemplate.GetContainers
        Return actionContainersManager.GetContainers()
    End Function
    Public Overridable Sub SetView(ByVal view As DevExpress.ExpressApp.View) Implements IFrameTemplate.SetView
        Me.view = view
        viewSitePanel.Controls.Clear()
        If view IsNot Nothing Then
            view.CreateControls()
            Dim viewControl As Control = CType(view.Control, Control)
            If viewControl IsNot Nothing Then
                viewControl.Dock = DockStyle.Fill
                viewSitePanel.SuspendLayout()
                Try
                    If TypeOf viewControl Is ISupportUpdate Then
                        CType(viewControl, ISupportUpdate).BeginUpdate()
                    End If
                    viewSitePanel.Controls.Add(viewControl)
                    If TypeOf viewControl Is ISupportUpdate Then
                        CType(viewControl, ISupportUpdate).EndUpdate()
                    End If
                Finally
                    viewSitePanel.ResumeLayout()
                End Try
            End If
            RaiseEvent ViewChanged(Me, New TemplateViewChangedEventArgs(view))
            If view.Model IsNot Nothing Then
                Dim imageName As String = ViewImageNameHelper.GetImageName(view)
                NativeMethods.SetFormIcon(Me, ImageLoader.Instance.GetImageInfo(imageName).Image, ImageLoader.Instance.GetLargeImageInfo(imageName).Image)
            Else
                NativeMethods.SetFormIcon(Me, NativeMethods.ExeIconSmall, NativeMethods.ExeIconLarge)
            End If
            Text = view.Caption
            MoveFocusToFirstViewControl()
        End If
    End Sub
    Private Function GetFormStateNode() As IModelFormState
        Dim viewId As String
        If view IsNot Nothing Then
            viewId = view.Id
        Else
            viewId = "Default"
        End If
        Dim result As IModelFormState = DirectCast(modelTemplate.FormStates, IModelList(Of IModelFormState))(viewId)
        If result Is Nothing Then
            result = modelTemplate.FormStates.AddNode(Of IModelFormState)(viewId)
        End If
        Return result
    End Function
    Private modelTemplate As IModelTemplateWin
    Public Overridable Sub SetSettings(ByVal modelTemplate As IModelTemplate) Implements ISupportStoreSettings.SetSettings
        Me.modelTemplate = CType(modelTemplate, IModelTemplateWin)
        locaizationHelper = New TemplatesHelper(Me.modelTemplate)
        formStateModelSynchronizer.Model = GetFormStateNode()
        autoShrink_Renamed = autoShrink_Renamed AndAlso Not IsSizeable
        ReloadSettings()
    End Sub
    Public Sub ReloadSettings() Implements ISupportStoreSettings.ReloadSettings
        ReloadSettingsCore()
        OnSettingsReloaded()
    End Sub
    Public Overridable Sub SaveSettings() Implements ISupportStoreSettings.SaveSettings
        If modelTemplate IsNot Nothing AndAlso IsSizeable Then
            formStateModelSynchronizer.SynchronizeModel()
        End If
    End Sub
    Public Event SettingsReloaded As EventHandler Implements ISupportStoreSettings.SettingsReloaded
    Public Overridable Sub SetStatus(ByVal messages() As String)
    End Sub
    Public Overridable Sub SetStatus(ByVal statusMessages As System.Collections.Generic.ICollection(Of String)) Implements IWindowTemplate.SetStatus
    End Sub
    Public Overridable Sub SetCaption(ByVal caption As String) Implements IWindowTemplate.SetCaption
    End Sub
    Public ReadOnly Property DefaultContainer() As IActionContainer Implements IFrameTemplate.DefaultContainer
        Get
            Return actionContainersManager.DefaultContainer
        End Get
    End Property
    Public Overridable Property IsSizeable() As Boolean Implements IWindowTemplate.IsSizeable
        Get
            Return FormBorderStyle = FormBorderStyle.Sizable
        End Get
        Set(ByVal value As Boolean)
            Dim storedBounds As Rectangle = DesktopBounds
            If value Then
                FormBorderStyle = FormBorderStyle.Sizable
            Else
                FormBorderStyle = FormBorderStyle.FixedDialog
            End If
            DesktopBounds = storedBounds
            MinimizeBox = value
            MaximizeBox = value
        End Set
    End Property
    Public ReadOnly Property ButtonsContainer() As ButtonsContainer
        Get
            Return buttonsContainer_Renamed
        End Get
    End Property
    Public Property AutoShrink() As Boolean
        Get
            Return autoShrink_Renamed
        End Get
        Set(ByVal value As Boolean)
            autoShrink_Renamed = value
        End Set
    End Property
    Public ReadOnly Property ViewSiteControl() As Object Implements IViewSiteTemplate.ViewSiteControl
        Get
            Return viewSitePanel
        End Get
    End Property
    Public Event CustomizeClientSize As EventHandler(Of CustomSizeEventArgs)
    Public Event CustomizeMinimumSize As EventHandler(Of CustomSizeEventArgs)
    Public Event BarManagerChanged As EventHandler Implements IBarManagerHolder.BarManagerChanged
#Region "IBarManagerHolder Members"

    Public ReadOnly Property BarManager() As DevExpress.XtraBars.BarManager Implements IBarManagerHolder.BarManager
        Get
            Return xafBarManager
        End Get
    End Property

#End Region

#Region "ISupportViewChanged Members"

    Public Event ViewChanged As EventHandler(Of TemplateViewChangedEventArgs) Implements ISupportViewChanged.ViewChanged

#End Region
End Class